<html><!-- Created using the cpp_pretty_printer from the dlib C++ library.  See http://dlib.net for updates. --><head><title>dlib C++ Library - widgets.h</title></head><body bgcolor='white'><pre>
<font color='#009900'>// Copyright (C) 2005  Davis E. King (davis@dlib.net), Keita Mochizuki
</font><font color='#009900'>// License: Boost Software License   See LICENSE.txt for the full license.
</font>
<font color='#0000FF'>#ifndef</font> DLIB_WIDGETs_
<font color='#0000FF'>#define</font> DLIB_WIDGETs_

<font color='#0000FF'>#include</font> "<a style='text-decoration:none' href='../algs.h.html'>../algs.h</a>"
<font color='#0000FF'>#include</font> "<a style='text-decoration:none' href='widgets_abstract.h.html'>widgets_abstract.h</a>"
<font color='#0000FF'>#include</font> "<a style='text-decoration:none' href='drawable.h.html'>drawable.h</a>"
<font color='#0000FF'>#include</font> "<a style='text-decoration:none' href='../gui_core.h.html'>../gui_core.h</a>"
<font color='#0000FF'>#include</font> "<a style='text-decoration:none' href='fonts.h.html'>fonts.h</a>"
<font color='#0000FF'>#include</font> <font color='#5555FF'>&lt;</font>string<font color='#5555FF'>&gt;</font>
<font color='#0000FF'>#include</font> <font color='#5555FF'>&lt;</font>sstream<font color='#5555FF'>&gt;</font>
<font color='#0000FF'>#include</font> "<a style='text-decoration:none' href='../timer.h.html'>../timer.h</a>"
<font color='#0000FF'>#include</font> "<a style='text-decoration:none' href='base_widgets.h.html'>base_widgets.h</a>"
<font color='#0000FF'>#include</font> "<a style='text-decoration:none' href='../member_function_pointer.h.html'>../member_function_pointer.h</a>"
<font color='#0000FF'>#include</font> "<a style='text-decoration:none' href='../array.h.html'>../array.h</a>"
<font color='#0000FF'>#include</font> "<a style='text-decoration:none' href='../array2d.h.html'>../array2d.h</a>"
<font color='#0000FF'>#include</font> "<a style='text-decoration:none' href='../sequence.h.html'>../sequence.h</a>"
<font color='#0000FF'>#include</font> "<a style='text-decoration:none' href='../dir_nav.h.html'>../dir_nav.h</a>"
<font color='#0000FF'>#include</font> "<a style='text-decoration:none' href='../queue.h.html'>../queue.h</a>"
<font color='#0000FF'>#include</font> "<a style='text-decoration:none' href='../smart_pointers.h.html'>../smart_pointers.h</a>"
<font color='#0000FF'>#include</font> "<a style='text-decoration:none' href='style.h.html'>style.h</a>"
<font color='#0000FF'>#include</font> "<a style='text-decoration:none' href='../string.h.html'>../string.h</a>"
<font color='#0000FF'>#include</font> "<a style='text-decoration:none' href='../misc_api.h.html'>../misc_api.h</a>"
<font color='#0000FF'>#include</font> <font color='#5555FF'>&lt;</font>cctype<font color='#5555FF'>&gt;</font>
<font color='#0000FF'>#include</font> <font color='#5555FF'>&lt;</font>vector<font color='#5555FF'>&gt;</font>
<font color='#0000FF'>#include</font> "<a style='text-decoration:none' href='../any.h.html'>../any.h</a>"
<font color='#0000FF'>#include</font> <font color='#5555FF'>&lt;</font>set<font color='#5555FF'>&gt;</font>
<font color='#0000FF'>#include</font> "<a style='text-decoration:none' href='../image_processing/full_object_detection.h.html'>../image_processing/full_object_detection.h</a>"

<font color='#0000FF'>#ifdef</font> _MSC_VER
<font color='#009900'>// This #pragma directive is also located in the algs.h file but for whatever
</font><font color='#009900'>// reason visual studio 9 just ignores it when it is only there. 
</font>
<font color='#009900'>// this is to disable the "'this' : used in base member initializer list"
</font><font color='#009900'>// warning you get from some of the GUI objects since all the objects
</font><font color='#009900'>// require that their parent class be passed into their constructor. 
</font><font color='#009900'>// In this case though it is totally safe so it is ok to disable this warning.
</font><font color='#0000FF'>#pragma</font> warning<font face='Lucida Console'>(</font>disable : <font color='#979000'>4355</font><font face='Lucida Console'>)</font>
<font color='#0000FF'>#endif</font>

<font color='#0000FF'>namespace</font> dlib
<b>{</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font><font color='#009900'>// ----------------------------------------------------------------------------------------
</font>    <font color='#009900'>// class label  
</font><font color='#009900'>// ----------------------------------------------------------------------------------------
</font><font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'>class</font> <b><a name='label'></a>label</b> : <font color='#0000FF'>public</font> drawable
    <b>{</b>
    <font color='#0000FF'>public</font>:
        <b><a name='label'></a>label</b><font face='Lucida Console'>(</font>
            drawable_window<font color='#5555FF'>&amp;</font> w
        <font face='Lucida Console'>)</font> : 
            drawable<font face='Lucida Console'>(</font>w<font face='Lucida Console'>)</font>,
            text_color_<font face='Lucida Console'>(</font><font color='#979000'>0</font>,<font color='#979000'>0</font>,<font color='#979000'>0</font><font face='Lucida Console'>)</font>
        <b>{</b>
            <font color='#BB00BB'>enable_events</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
        <b>}</b>

        ~<b><a name='label'></a>label</b><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>
        <b>{</b> <font color='#BB00BB'>disable_events</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>; parent.<font color='#BB00BB'>invalidate_rectangle</font><font face='Lucida Console'>(</font>rect<font face='Lucida Console'>)</font>; <b>}</b>

        <font color='#0000FF'><u>void</u></font> <b><a name='set_text'></a>set_text</b> <font face='Lucida Console'>(</font>
            <font color='#0000FF'>const</font> std::string<font color='#5555FF'>&amp;</font> text
        <font face='Lucida Console'>)</font>;

        <font color='#0000FF'><u>void</u></font> <b><a name='set_text'></a>set_text</b> <font face='Lucida Console'>(</font>
            <font color='#0000FF'>const</font> std::wstring<font color='#5555FF'>&amp;</font> text
        <font face='Lucida Console'>)</font>;

        <font color='#0000FF'><u>void</u></font> <b><a name='set_text'></a>set_text</b> <font face='Lucida Console'>(</font>
            <font color='#0000FF'>const</font> dlib::ustring<font color='#5555FF'>&amp;</font> text
        <font face='Lucida Console'>)</font>;

        <font color='#0000FF'>const</font> std::string <b><a name='text'></a>text</b> <font face='Lucida Console'>(</font>
        <font face='Lucida Console'>)</font> <font color='#0000FF'>const</font>;

        <font color='#0000FF'>const</font> std::wstring <b><a name='wtext'></a>wtext</b> <font face='Lucida Console'>(</font>
        <font face='Lucida Console'>)</font> <font color='#0000FF'>const</font>;

        <font color='#0000FF'>const</font> dlib::ustring <b><a name='utext'></a>utext</b> <font face='Lucida Console'>(</font>
        <font face='Lucida Console'>)</font> <font color='#0000FF'>const</font>;

        <font color='#0000FF'><u>void</u></font> <b><a name='set_text_color'></a>set_text_color</b> <font face='Lucida Console'>(</font>
            <font color='#0000FF'>const</font> rgb_pixel color
        <font face='Lucida Console'>)</font>;

        <font color='#0000FF'>const</font> rgb_pixel <b><a name='text_color'></a>text_color</b> <font face='Lucida Console'>(</font>
        <font face='Lucida Console'>)</font> <font color='#0000FF'>const</font>;

        <font color='#0000FF'><u>void</u></font> <b><a name='set_main_font'></a>set_main_font</b> <font face='Lucida Console'>(</font>
            <font color='#0000FF'>const</font> shared_ptr_thread_safe<font color='#5555FF'>&lt;</font>font<font color='#5555FF'>&gt;</font><font color='#5555FF'>&amp;</font> f
        <font face='Lucida Console'>)</font>;

    <font color='#0000FF'>private</font>:
        dlib::ustring text_;
        rgb_pixel text_color_;


        <font color='#009900'>// restricted functions
</font>        <b><a name='label'></a>label</b><font face='Lucida Console'>(</font>label<font color='#5555FF'>&amp;</font><font face='Lucida Console'>)</font>;        <font color='#009900'>// copy constructor
</font>        label<font color='#5555FF'>&amp;</font> <b><a name='operator'></a>operator</b><font color='#5555FF'>=</font><font face='Lucida Console'>(</font>label<font color='#5555FF'>&amp;</font><font face='Lucida Console'>)</font>;    <font color='#009900'>// assignment operator
</font>
    <font color='#0000FF'>protected</font>:

        <font color='#0000FF'><u>void</u></font> <b><a name='draw'></a>draw</b> <font face='Lucida Console'>(</font>
            <font color='#0000FF'>const</font> canvas<font color='#5555FF'>&amp;</font> c
        <font face='Lucida Console'>)</font> <font color='#0000FF'>const</font>;

    <b>}</b>;

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font><font color='#009900'>// ----------------------------------------------------------------------------------------
</font>    <font color='#009900'>// class toggle_button
</font><font color='#009900'>// ----------------------------------------------------------------------------------------
</font><font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'>class</font> <b><a name='toggle_button'></a>toggle_button</b> : <font color='#0000FF'>public</font> button_action 
    <b>{</b>
        <font color='#009900'>/*!
            INITIAL VALUE
                - checked == false

            CONVENTION
                - is_checked() == checked
        !*/</font>

    <font color='#0000FF'>public</font>:

        <b><a name='toggle_button'></a>toggle_button</b><font face='Lucida Console'>(</font>
            drawable_window<font color='#5555FF'>&amp;</font> w
        <font face='Lucida Console'>)</font> : 
            button_action<font face='Lucida Console'>(</font>w<font face='Lucida Console'>)</font>,
            btn_tooltip<font face='Lucida Console'>(</font>w<font face='Lucida Console'>)</font>,
            checked<font face='Lucida Console'>(</font><font color='#979000'>false</font><font face='Lucida Console'>)</font>
        <b>{</b>
            style.<font color='#BB00BB'>reset</font><font face='Lucida Console'>(</font><font color='#0000FF'>new</font> <font color='#BB00BB'>toggle_button_style_default</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
            <font color='#BB00BB'>enable_events</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
        <b>}</b>
        
        ~<b><a name='toggle_button'></a>toggle_button</b><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <b>{</b> <font color='#BB00BB'>disable_events</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>; parent.<font color='#BB00BB'>invalidate_rectangle</font><font face='Lucida Console'>(</font>rect<font face='Lucida Console'>)</font>; <b>}</b>

        <font color='#0000FF'><u>void</u></font> <b><a name='set_name'></a>set_name</b> <font face='Lucida Console'>(</font>
            <font color='#0000FF'>const</font> std::string<font color='#5555FF'>&amp;</font> name
        <font face='Lucida Console'>)</font>;

        <font color='#0000FF'><u>void</u></font> <b><a name='set_name'></a>set_name</b> <font face='Lucida Console'>(</font>
            <font color='#0000FF'>const</font> std::wstring<font color='#5555FF'>&amp;</font> name
        <font face='Lucida Console'>)</font>;

        <font color='#0000FF'><u>void</u></font> <b><a name='set_name'></a>set_name</b> <font face='Lucida Console'>(</font>
            <font color='#0000FF'>const</font> dlib::ustring<font color='#5555FF'>&amp;</font> name
        <font face='Lucida Console'>)</font>;

        <font color='#0000FF'><u>void</u></font> <b><a name='set_size'></a>set_size</b> <font face='Lucida Console'>(</font>
            <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> width_,
            <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> height_
        <font face='Lucida Console'>)</font>;

        <font color='#0000FF'><u>void</u></font> <b><a name='set_tooltip_text'></a>set_tooltip_text</b> <font face='Lucida Console'>(</font>
            <font color='#0000FF'>const</font> std::string<font color='#5555FF'>&amp;</font> text
        <font face='Lucida Console'>)</font>;

        <font color='#0000FF'><u>void</u></font> <b><a name='set_tooltip_text'></a>set_tooltip_text</b> <font face='Lucida Console'>(</font>
            <font color='#0000FF'>const</font> std::wstring<font color='#5555FF'>&amp;</font> text
        <font face='Lucida Console'>)</font>;

        <font color='#0000FF'><u>void</u></font> <b><a name='set_tooltip_text'></a>set_tooltip_text</b> <font face='Lucida Console'>(</font>
            <font color='#0000FF'>const</font> ustring<font color='#5555FF'>&amp;</font> text
        <font face='Lucida Console'>)</font>;

        <font color='#0000FF'>const</font> std::string <b><a name='tooltip_text'></a>tooltip_text</b> <font face='Lucida Console'>(</font>
        <font face='Lucida Console'>)</font> <font color='#0000FF'>const</font>;

        <font color='#0000FF'>const</font> std::wstring <b><a name='tooltip_wtext'></a>tooltip_wtext</b> <font face='Lucida Console'>(</font>
        <font face='Lucida Console'>)</font> <font color='#0000FF'>const</font>;

        <font color='#0000FF'>const</font> dlib::ustring <b><a name='tooltip_utext'></a>tooltip_utext</b> <font face='Lucida Console'>(</font>
        <font face='Lucida Console'>)</font> <font color='#0000FF'>const</font>;

        <font color='#0000FF'><u>bool</u></font> <b><a name='is_checked'></a>is_checked</b> <font face='Lucida Console'>(</font>
        <font face='Lucida Console'>)</font> <font color='#0000FF'>const</font>;

        <font color='#0000FF'>const</font> std::string <b><a name='name'></a>name</b> <font face='Lucida Console'>(</font>
        <font face='Lucida Console'>)</font> <font color='#0000FF'>const</font>;

        <font color='#0000FF'>const</font> std::wstring <b><a name='wname'></a>wname</b> <font face='Lucida Console'>(</font>
        <font face='Lucida Console'>)</font> <font color='#0000FF'>const</font>;

        <font color='#0000FF'>const</font> dlib::ustring <b><a name='uname'></a>uname</b> <font face='Lucida Console'>(</font>
        <font face='Lucida Console'>)</font> <font color='#0000FF'>const</font>;

        <font color='#0000FF'><u>void</u></font> <b><a name='set_checked'></a>set_checked</b> <font face='Lucida Console'>(</font>
        <font face='Lucida Console'>)</font>;

        <font color='#0000FF'><u>void</u></font> <b><a name='set_unchecked'></a>set_unchecked</b> <font face='Lucida Console'>(</font>
        <font face='Lucida Console'>)</font>;

        <font color='#0000FF'><u>void</u></font> <b><a name='show'></a>show</b> <font face='Lucida Console'>(</font>
        <font face='Lucida Console'>)</font>;

        <font color='#0000FF'><u>void</u></font> <b><a name='hide'></a>hide</b> <font face='Lucida Console'>(</font>
        <font face='Lucida Console'>)</font>;

        <font color='#0000FF'><u>void</u></font> <b><a name='enable'></a>enable</b> <font face='Lucida Console'>(</font>
        <font face='Lucida Console'>)</font>;

        <font color='#0000FF'><u>void</u></font> <b><a name='disable'></a>disable</b> <font face='Lucida Console'>(</font>
        <font face='Lucida Console'>)</font>;

        <font color='#0000FF'><u>void</u></font> <b><a name='set_main_font'></a>set_main_font</b> <font face='Lucida Console'>(</font>
            <font color='#0000FF'>const</font> shared_ptr_thread_safe<font color='#5555FF'>&lt;</font>font<font color='#5555FF'>&gt;</font><font color='#5555FF'>&amp;</font> f
        <font face='Lucida Console'>)</font>;

        <font color='#0000FF'><u>void</u></font> <b><a name='set_pos'></a>set_pos</b> <font face='Lucida Console'>(</font>
            <font color='#0000FF'><u>long</u></font> x,
            <font color='#0000FF'><u>long</u></font> y
        <font face='Lucida Console'>)</font>;

        <font color='#0000FF'>template</font> <font color='#5555FF'>&lt;</font>
            <font color='#0000FF'>typename</font> style_type
            <font color='#5555FF'>&gt;</font>
        <font color='#0000FF'><u>void</u></font> <b><a name='set_style'></a>set_style</b> <font face='Lucida Console'>(</font>
            <font color='#0000FF'>const</font> style_type<font color='#5555FF'>&amp;</font> style_
        <font face='Lucida Console'>)</font>
        <b>{</b>
            auto_mutex <font color='#BB00BB'>M</font><font face='Lucida Console'>(</font>m<font face='Lucida Console'>)</font>;
            style.<font color='#BB00BB'>reset</font><font face='Lucida Console'>(</font><font color='#0000FF'>new</font> <font color='#BB00BB'>style_type</font><font face='Lucida Console'>(</font>style_<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
            rect <font color='#5555FF'>=</font> <font color='#BB00BB'>move_rect</font><font face='Lucida Console'>(</font>style<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font><font color='#BB00BB'>get_min_size</font><font face='Lucida Console'>(</font>name_,<font color='#5555FF'>*</font>mfont<font face='Lucida Console'>)</font>, rect.<font color='#BB00BB'>left</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>, rect.<font color='#BB00BB'>top</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
            parent.<font color='#BB00BB'>invalidate_rectangle</font><font face='Lucida Console'>(</font>rect<font face='Lucida Console'>)</font>;
        <b>}</b>

        <font color='#0000FF'>template</font> <font color='#5555FF'>&lt;</font>
            <font color='#0000FF'>typename</font> T
            <font color='#5555FF'>&gt;</font>
        <font color='#0000FF'><u>void</u></font> <b><a name='set_click_handler'></a>set_click_handler</b> <font face='Lucida Console'>(</font>
            T<font color='#5555FF'>&amp;</font> object,
            <font color='#0000FF'><u>void</u></font> <font face='Lucida Console'>(</font>T::<font color='#5555FF'>*</font>event_handler_<font face='Lucida Console'>)</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>
        <font face='Lucida Console'>)</font>
        <b>{</b>
            auto_mutex <font color='#BB00BB'>M</font><font face='Lucida Console'>(</font>m<font face='Lucida Console'>)</font>;
            event_handler <font color='#5555FF'>=</font> <font color='#BB00BB'>make_mfp</font><font face='Lucida Console'>(</font>object,event_handler_<font face='Lucida Console'>)</font>;
            event_handler_self.<font color='#BB00BB'>clear</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
        <b>}</b>

        <font color='#0000FF'><u>void</u></font> <b><a name='set_click_handler'></a>set_click_handler</b> <font face='Lucida Console'>(</font>
            <font color='#0000FF'>const</font> any_function<font color='#5555FF'>&lt;</font><font color='#0000FF'><u>void</u></font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>&gt;</font><font color='#5555FF'>&amp;</font> event_handler_
        <font face='Lucida Console'>)</font>
        <b>{</b>
            auto_mutex <font color='#BB00BB'>M</font><font face='Lucida Console'>(</font>m<font face='Lucida Console'>)</font>;
            event_handler <font color='#5555FF'>=</font> event_handler_;
            event_handler_self.<font color='#BB00BB'>clear</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
        <b>}</b>

        <font color='#0000FF'>template</font> <font color='#5555FF'>&lt;</font>
            <font color='#0000FF'>typename</font> T
            <font color='#5555FF'>&gt;</font>
        <font color='#0000FF'><u>void</u></font> <b><a name='set_click_handler'></a>set_click_handler</b> <font face='Lucida Console'>(</font>
            T<font color='#5555FF'>&amp;</font> object,
            <font color='#0000FF'><u>void</u></font> <font face='Lucida Console'>(</font>T::<font color='#5555FF'>*</font>event_handler_<font face='Lucida Console'>)</font><font face='Lucida Console'>(</font>toggle_button<font color='#5555FF'>&amp;</font><font face='Lucida Console'>)</font>
        <font face='Lucida Console'>)</font>
        <b>{</b>
            auto_mutex <font color='#BB00BB'>M</font><font face='Lucida Console'>(</font>m<font face='Lucida Console'>)</font>;
            event_handler_self <font color='#5555FF'>=</font> <font color='#BB00BB'>make_mfp</font><font face='Lucida Console'>(</font>object,event_handler_<font face='Lucida Console'>)</font>;
            event_handler.<font color='#BB00BB'>clear</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
        <b>}</b>

        <font color='#0000FF'><u>void</u></font> <b><a name='set_sourced_click_handler'></a>set_sourced_click_handler</b> <font face='Lucida Console'>(</font>
            <font color='#0000FF'>const</font> any_function<font color='#5555FF'>&lt;</font><font color='#0000FF'><u>void</u></font><font face='Lucida Console'>(</font>toggle_button<font color='#5555FF'>&amp;</font><font face='Lucida Console'>)</font><font color='#5555FF'>&gt;</font><font color='#5555FF'>&amp;</font> event_handler_
        <font face='Lucida Console'>)</font>
        <b>{</b>
            auto_mutex <font color='#BB00BB'>M</font><font face='Lucida Console'>(</font>m<font face='Lucida Console'>)</font>;
            event_handler_self <font color='#5555FF'>=</font> event_handler_;
            event_handler.<font color='#BB00BB'>clear</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
        <b>}</b>

    <font color='#0000FF'>private</font>:

        <font color='#009900'>// restricted functions
</font>        <b><a name='toggle_button'></a>toggle_button</b><font face='Lucida Console'>(</font>toggle_button<font color='#5555FF'>&amp;</font><font face='Lucida Console'>)</font>;        <font color='#009900'>// copy constructor
</font>        toggle_button<font color='#5555FF'>&amp;</font> <b><a name='operator'></a>operator</b><font color='#5555FF'>=</font><font face='Lucida Console'>(</font>toggle_button<font color='#5555FF'>&amp;</font><font face='Lucida Console'>)</font>;    <font color='#009900'>// assignment operator
</font>
        dlib::ustring name_;
        tooltip btn_tooltip;
        <font color='#0000FF'><u>bool</u></font> checked;

        any_function<font color='#5555FF'>&lt;</font><font color='#0000FF'><u>void</u></font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>&gt;</font> event_handler;
        any_function<font color='#5555FF'>&lt;</font><font color='#0000FF'><u>void</u></font><font face='Lucida Console'>(</font>toggle_button<font color='#5555FF'>&amp;</font><font face='Lucida Console'>)</font><font color='#5555FF'>&gt;</font> event_handler_self;

        scoped_ptr<font color='#5555FF'>&lt;</font>toggle_button_style<font color='#5555FF'>&gt;</font> style;

    <font color='#0000FF'>protected</font>:

        <font color='#0000FF'><u>void</u></font> <b><a name='draw'></a>draw</b> <font face='Lucida Console'>(</font>
            <font color='#0000FF'>const</font> canvas<font color='#5555FF'>&amp;</font> c
        <font face='Lucida Console'>)</font> <font color='#0000FF'>const</font> <b>{</b> style<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font><font color='#BB00BB'>draw_toggle_button</font><font face='Lucida Console'>(</font>c,rect,enabled,<font color='#5555FF'>*</font>mfont,lastx,lasty,name_,<font color='#BB00BB'>is_depressed</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>,checked<font face='Lucida Console'>)</font>; <b>}</b>

        <font color='#0000FF'><u>void</u></font> <b><a name='on_button_up'></a>on_button_up</b> <font face='Lucida Console'>(</font>
            <font color='#0000FF'><u>bool</u></font> mouse_over
        <font face='Lucida Console'>)</font>;

        <font color='#0000FF'><u>void</u></font> <b><a name='on_mouse_over'></a>on_mouse_over</b> <font face='Lucida Console'>(</font>
        <font face='Lucida Console'>)</font><b>{</b> <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>style<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font><font color='#BB00BB'>redraw_on_mouse_over</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font> parent.<font color='#BB00BB'>invalidate_rectangle</font><font face='Lucida Console'>(</font>rect<font face='Lucida Console'>)</font>; <b>}</b>

        <font color='#0000FF'><u>void</u></font> <b><a name='on_mouse_not_over'></a>on_mouse_not_over</b> <font face='Lucida Console'>(</font>
        <font face='Lucida Console'>)</font><b>{</b> <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>style<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font><font color='#BB00BB'>redraw_on_mouse_over</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font> parent.<font color='#BB00BB'>invalidate_rectangle</font><font face='Lucida Console'>(</font>rect<font face='Lucida Console'>)</font>; <b>}</b>
    <b>}</b>;
 
<font color='#009900'>// ----------------------------------------------------------------------------------------
</font><font color='#009900'>// ----------------------------------------------------------------------------------------
</font>    <font color='#009900'>// class text_field  
</font><font color='#009900'>// ----------------------------------------------------------------------------------------
</font><font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'>class</font> <b><a name='text_field'></a>text_field</b> : <font color='#0000FF'>public</font> drawable
    <b>{</b>
        <font color='#009900'>/*!
            INITIAL VALUE
                text_color_ == rgb_pixel(0,0,0)
                bg_color_ == rgb_pixel(255,255,255)
                cursor_pos == 0
                text_width == 0
                text_ == ""
                has_focus == false
                cursor_visible == false
                recent_movement == false
                highlight_start == 0
                highlight_end == -1
                shift_pos == -1
                text_pos == 0
    
            CONVENTION
                - cursor_pos == the position of the cursor in the string text_.  The 
                  cursor appears before the letter text_[cursor_pos]
                - cursor_x == the x coordinate of the cursor relative to the left side 
                  of rect.  i.e. the number of pixels that separate the cursor from the
                  left side of the text_field.
                - has_focus == true if this text field has keyboard input focus
                - cursor_visible == true if the cursor should be painted
                - text_ == text()
                - text_pos == the index of the first letter in text_ that appears in 
                  this text field.
                - text_width == the width of text_[text_pos] though text_[text.size()-1]

                - if (has_focus &amp;&amp; the user has recently moved the cursor) then
                    - recent_movement == true
                - else
                    - recent_movement == false

                - if (highlight_start &lt;= highlight_end) then
                    - text[highlight_start] though text[highlight_end] should be
                      highlighted

                - if (shift_pos != -1) then
                    - has_focus == true
                    - the shift key is being held down or the left mouse button is
                      being held down.
                    - shift_pos == the position of the cursor when the shift or mouse key
                      was first pressed.

                - text_color() == text_color_
                - background_color() == bg_color_
        !*/</font>

    <font color='#0000FF'>public</font>:
        <b><a name='text_field'></a>text_field</b><font face='Lucida Console'>(</font>
            drawable_window<font color='#5555FF'>&amp;</font> w
        <font face='Lucida Console'>)</font> : 
            drawable<font face='Lucida Console'>(</font>w,MOUSE_CLICK <font color='#5555FF'>|</font> KEYBOARD_EVENTS <font color='#5555FF'>|</font> MOUSE_MOVE <font color='#5555FF'>|</font> STRING_PUT<font face='Lucida Console'>)</font>,
            text_color_<font face='Lucida Console'>(</font><font color='#979000'>0</font>,<font color='#979000'>0</font>,<font color='#979000'>0</font><font face='Lucida Console'>)</font>,
            bg_color_<font face='Lucida Console'>(</font><font color='#979000'>255</font>,<font color='#979000'>255</font>,<font color='#979000'>255</font><font face='Lucida Console'>)</font>,
            text_width<font face='Lucida Console'>(</font><font color='#979000'>0</font><font face='Lucida Console'>)</font>,
            text_pos<font face='Lucida Console'>(</font><font color='#979000'>0</font><font face='Lucida Console'>)</font>,
            recent_movement<font face='Lucida Console'>(</font><font color='#979000'>false</font><font face='Lucida Console'>)</font>,
            has_focus<font face='Lucida Console'>(</font><font color='#979000'>false</font><font face='Lucida Console'>)</font>,
            cursor_visible<font face='Lucida Console'>(</font><font color='#979000'>false</font><font face='Lucida Console'>)</font>,
            cursor_pos<font face='Lucida Console'>(</font><font color='#979000'>0</font><font face='Lucida Console'>)</font>,
            highlight_start<font face='Lucida Console'>(</font><font color='#979000'>0</font><font face='Lucida Console'>)</font>,
            highlight_end<font face='Lucida Console'>(</font><font color='#5555FF'>-</font><font color='#979000'>1</font><font face='Lucida Console'>)</font>,
            shift_pos<font face='Lucida Console'>(</font><font color='#5555FF'>-</font><font color='#979000'>1</font><font face='Lucida Console'>)</font>,
            t<font face='Lucida Console'>(</font><font color='#5555FF'>*</font><font color='#0000FF'>this</font>,<font color='#5555FF'>&amp;</font>text_field::timer_action<font face='Lucida Console'>)</font>,
            right_click_menu<font face='Lucida Console'>(</font>w<font face='Lucida Console'>)</font>
        <b>{</b>
            style.<font color='#BB00BB'>reset</font><font face='Lucida Console'>(</font><font color='#0000FF'>new</font> <font color='#BB00BB'>text_field_style_default</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
            rect.<font color='#BB00BB'>set_bottom</font><font face='Lucida Console'>(</font>mfont<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font><font color='#BB00BB'>height</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>+</font> <font face='Lucida Console'>(</font>style<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font><font color='#BB00BB'>get_padding</font><font face='Lucida Console'>(</font><font color='#5555FF'>*</font>mfont<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font><font color='#5555FF'>*</font><font color='#979000'>2</font><font face='Lucida Console'>)</font>;
            rect.<font color='#BB00BB'>set_right</font><font face='Lucida Console'>(</font><font face='Lucida Console'>(</font>style<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font><font color='#BB00BB'>get_padding</font><font face='Lucida Console'>(</font><font color='#5555FF'>*</font>mfont<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font><font color='#5555FF'>*</font><font color='#979000'>2</font><font face='Lucida Console'>)</font>;
            cursor_x <font color='#5555FF'>=</font> style<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font><font color='#BB00BB'>get_padding</font><font face='Lucida Console'>(</font><font color='#5555FF'>*</font>mfont<font face='Lucida Console'>)</font>;

            right_click_menu.<font color='#BB00BB'>menu</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>.<font color='#BB00BB'>add_menu_item</font><font face='Lucida Console'>(</font><font color='#BB00BB'>menu_item_text</font><font face='Lucida Console'>(</font>"<font color='#CC0000'>Cut</font>",<font color='#5555FF'>*</font><font color='#0000FF'>this</font>,<font color='#5555FF'>&amp;</font>text_field::on_cut,'<font color='#FF0000'>t</font>'<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
            right_click_menu.<font color='#BB00BB'>menu</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>.<font color='#BB00BB'>add_menu_item</font><font face='Lucida Console'>(</font><font color='#BB00BB'>menu_item_text</font><font face='Lucida Console'>(</font>"<font color='#CC0000'>Copy</font>",<font color='#5555FF'>*</font><font color='#0000FF'>this</font>,<font color='#5555FF'>&amp;</font>text_field::on_copy,'<font color='#FF0000'>C</font>'<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
            right_click_menu.<font color='#BB00BB'>menu</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>.<font color='#BB00BB'>add_menu_item</font><font face='Lucida Console'>(</font><font color='#BB00BB'>menu_item_text</font><font face='Lucida Console'>(</font>"<font color='#CC0000'>Paste</font>",<font color='#5555FF'>*</font><font color='#0000FF'>this</font>,<font color='#5555FF'>&amp;</font>text_field::on_paste,'<font color='#FF0000'>P</font>'<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
            right_click_menu.<font color='#BB00BB'>menu</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>.<font color='#BB00BB'>add_menu_item</font><font face='Lucida Console'>(</font><font color='#BB00BB'>menu_item_text</font><font face='Lucida Console'>(</font>"<font color='#CC0000'>Delete</font>",<font color='#5555FF'>*</font><font color='#0000FF'>this</font>,<font color='#5555FF'>&amp;</font>text_field::on_delete_selected,'<font color='#FF0000'>D</font>'<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
            right_click_menu.<font color='#BB00BB'>menu</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>.<font color='#BB00BB'>add_menu_item</font><font face='Lucida Console'>(</font><font color='#BB00BB'>menu_item_separator</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
            right_click_menu.<font color='#BB00BB'>menu</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>.<font color='#BB00BB'>add_menu_item</font><font face='Lucida Console'>(</font><font color='#BB00BB'>menu_item_text</font><font face='Lucida Console'>(</font>"<font color='#CC0000'>Select All</font>",<font color='#5555FF'>*</font><font color='#0000FF'>this</font>,<font color='#5555FF'>&amp;</font>text_field::on_select_all,'<font color='#FF0000'>A</font>'<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;

            right_click_menu.<font color='#BB00BB'>set_rect</font><font face='Lucida Console'>(</font><font color='#BB00BB'>get_text_rect</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
            <font color='#BB00BB'>enable_events</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;

            t.<font color='#BB00BB'>set_delay_time</font><font face='Lucida Console'>(</font><font color='#979000'>500</font><font face='Lucida Console'>)</font>;
        <b>}</b>

        ~<b><a name='text_field'></a>text_field</b> <font face='Lucida Console'>(</font>
        <font face='Lucida Console'>)</font>
        <b>{</b>
            <font color='#BB00BB'>disable_events</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
            parent.<font color='#BB00BB'>invalidate_rectangle</font><font face='Lucida Console'>(</font>rect<font face='Lucida Console'>)</font>; 
            t.<font color='#BB00BB'>stop_and_wait</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
        <b>}</b>

        <font color='#0000FF'>template</font> <font color='#5555FF'>&lt;</font>
            <font color='#0000FF'>typename</font> style_type
            <font color='#5555FF'>&gt;</font>
        <font color='#0000FF'><u>void</u></font> <b><a name='set_style'></a>set_style</b> <font face='Lucida Console'>(</font>
            <font color='#0000FF'>const</font> style_type<font color='#5555FF'>&amp;</font> style_
        <font face='Lucida Console'>)</font>
        <b>{</b>
            auto_mutex <font color='#BB00BB'>M</font><font face='Lucida Console'>(</font>m<font face='Lucida Console'>)</font>;
            style.<font color='#BB00BB'>reset</font><font face='Lucida Console'>(</font><font color='#0000FF'>new</font> <font color='#BB00BB'>style_type</font><font face='Lucida Console'>(</font>style_<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
            <font color='#009900'>// call this just so that this widget redraws itself with the new style
</font>            <font color='#BB00BB'>set_main_font</font><font face='Lucida Console'>(</font>mfont<font face='Lucida Console'>)</font>;
        <b>}</b>

        <font color='#0000FF'><u>void</u></font> <b><a name='set_text'></a>set_text</b> <font face='Lucida Console'>(</font>
            <font color='#0000FF'>const</font> std::string<font color='#5555FF'>&amp;</font> text_
        <font face='Lucida Console'>)</font>;

        <font color='#0000FF'><u>void</u></font> <b><a name='set_text'></a>set_text</b> <font face='Lucida Console'>(</font>
            <font color='#0000FF'>const</font> std::wstring<font color='#5555FF'>&amp;</font> text_
        <font face='Lucida Console'>)</font>;

        <font color='#0000FF'><u>void</u></font> <b><a name='give_input_focus'></a>give_input_focus</b> <font face='Lucida Console'>(</font>
        <font face='Lucida Console'>)</font>;

        <font color='#0000FF'><u>void</u></font> <b><a name='select_all_text'></a>select_all_text</b> <font face='Lucida Console'>(</font>
        <font face='Lucida Console'>)</font>;

        <font color='#0000FF'><u>void</u></font> <b><a name='set_text'></a>set_text</b> <font face='Lucida Console'>(</font>
            <font color='#0000FF'>const</font> dlib::ustring<font color='#5555FF'>&amp;</font> text_
        <font face='Lucida Console'>)</font>;

        <font color='#0000FF'>const</font> std::string <b><a name='text'></a>text</b> <font face='Lucida Console'>(</font>
        <font face='Lucida Console'>)</font> <font color='#0000FF'>const</font>;

        <font color='#0000FF'>const</font> std::wstring <b><a name='wtext'></a>wtext</b> <font face='Lucida Console'>(</font>
        <font face='Lucida Console'>)</font> <font color='#0000FF'>const</font>;

        <font color='#0000FF'>const</font> dlib::ustring <b><a name='utext'></a>utext</b> <font face='Lucida Console'>(</font>
        <font face='Lucida Console'>)</font> <font color='#0000FF'>const</font>;

        <font color='#0000FF'><u>void</u></font> <b><a name='set_text_color'></a>set_text_color</b> <font face='Lucida Console'>(</font>
            <font color='#0000FF'>const</font> rgb_pixel color
        <font face='Lucida Console'>)</font>;

        <font color='#0000FF'>const</font> rgb_pixel <b><a name='text_color'></a>text_color</b> <font face='Lucida Console'>(</font>
        <font face='Lucida Console'>)</font> <font color='#0000FF'>const</font>;

        <font color='#0000FF'><u>void</u></font> <b><a name='set_background_color'></a>set_background_color</b> <font face='Lucida Console'>(</font>
            <font color='#0000FF'>const</font> rgb_pixel color
        <font face='Lucida Console'>)</font>;

        <font color='#0000FF'>const</font> rgb_pixel <b><a name='background_color'></a>background_color</b> <font face='Lucida Console'>(</font>
        <font face='Lucida Console'>)</font> <font color='#0000FF'>const</font>;

        <font color='#0000FF'><u>void</u></font> <b><a name='set_width'></a>set_width</b> <font face='Lucida Console'>(</font>
            <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> width
        <font face='Lucida Console'>)</font>;

        <font color='#0000FF'><u>void</u></font> <b><a name='set_pos'></a>set_pos</b> <font face='Lucida Console'>(</font>
            <font color='#0000FF'><u>long</u></font> x,
            <font color='#0000FF'><u>long</u></font> y
        <font face='Lucida Console'>)</font>;

        <font color='#0000FF'><u>void</u></font> <b><a name='set_main_font'></a>set_main_font</b> <font face='Lucida Console'>(</font>
            <font color='#0000FF'>const</font> shared_ptr_thread_safe<font color='#5555FF'>&lt;</font>font<font color='#5555FF'>&gt;</font><font color='#5555FF'>&amp;</font> f
        <font face='Lucida Console'>)</font>;

        <font color='#0000FF'><u>int</u></font> <b><a name='next_free_user_event_number'></a>next_free_user_event_number</b> <font face='Lucida Console'>(</font>
        <font face='Lucida Console'>)</font> <font color='#0000FF'>const</font>
        <b>{</b>
            <font color='#0000FF'>return</font> drawable::<font color='#BB00BB'>next_free_user_event_number</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>+</font><font color='#979000'>1</font>;
        <b>}</b>

        <font color='#0000FF'><u>void</u></font> <b><a name='disable'></a>disable</b> <font face='Lucida Console'>(</font>
        <font face='Lucida Console'>)</font>;

        <font color='#0000FF'><u>void</u></font> <b><a name='enable'></a>enable</b> <font face='Lucida Console'>(</font>
        <font face='Lucida Console'>)</font>;

        <font color='#0000FF'><u>void</u></font> <b><a name='hide'></a>hide</b> <font face='Lucida Console'>(</font>
        <font face='Lucida Console'>)</font>;

        <font color='#0000FF'><u>void</u></font> <b><a name='show'></a>show</b> <font face='Lucida Console'>(</font>
        <font face='Lucida Console'>)</font>;

        <font color='#0000FF'>template</font> <font color='#5555FF'>&lt;</font>
            <font color='#0000FF'>typename</font> T
            <font color='#5555FF'>&gt;</font>
        <font color='#0000FF'><u>void</u></font> <b><a name='set_text_modified_handler'></a>set_text_modified_handler</b> <font face='Lucida Console'>(</font>
            T<font color='#5555FF'>&amp;</font> object,
            <font color='#0000FF'><u>void</u></font> <font face='Lucida Console'>(</font>T::<font color='#5555FF'>*</font>event_handler<font face='Lucida Console'>)</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>
        <font face='Lucida Console'>)</font>
        <b>{</b>
            auto_mutex <font color='#BB00BB'>M</font><font face='Lucida Console'>(</font>m<font face='Lucida Console'>)</font>;
            text_modified_handler <font color='#5555FF'>=</font> <font color='#BB00BB'>make_mfp</font><font face='Lucida Console'>(</font>object,event_handler<font face='Lucida Console'>)</font>;
        <b>}</b>

        <font color='#0000FF'>template</font> <font color='#5555FF'>&lt;</font>
            <font color='#0000FF'>typename</font> T
            <font color='#5555FF'>&gt;</font>
        <font color='#0000FF'><u>void</u></font> <b><a name='set_enter_key_handler'></a>set_enter_key_handler</b> <font face='Lucida Console'>(</font>
            T<font color='#5555FF'>&amp;</font> object,
            <font color='#0000FF'><u>void</u></font> <font face='Lucida Console'>(</font>T::<font color='#5555FF'>*</font>event_handler<font face='Lucida Console'>)</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>
        <font face='Lucida Console'>)</font>
        <b>{</b>
            auto_mutex <font color='#BB00BB'>M</font><font face='Lucida Console'>(</font>m<font face='Lucida Console'>)</font>;
            enter_key_handler <font color='#5555FF'>=</font> <font color='#BB00BB'>make_mfp</font><font face='Lucida Console'>(</font>object,event_handler<font face='Lucida Console'>)</font>;
        <b>}</b>

        <font color='#0000FF'><u>void</u></font> <b><a name='set_text_modified_handler'></a>set_text_modified_handler</b> <font face='Lucida Console'>(</font>
            <font color='#0000FF'>const</font> any_function<font color='#5555FF'>&lt;</font><font color='#0000FF'><u>void</u></font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>&gt;</font><font color='#5555FF'>&amp;</font> event_handler
        <font face='Lucida Console'>)</font>
        <b>{</b>
            auto_mutex <font color='#BB00BB'>M</font><font face='Lucida Console'>(</font>m<font face='Lucida Console'>)</font>;
            text_modified_handler <font color='#5555FF'>=</font> event_handler;
        <b>}</b>

        <font color='#0000FF'><u>void</u></font> <b><a name='set_enter_key_handler'></a>set_enter_key_handler</b> <font face='Lucida Console'>(</font>
            <font color='#0000FF'>const</font> any_function<font color='#5555FF'>&lt;</font><font color='#0000FF'><u>void</u></font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>&gt;</font><font color='#5555FF'>&amp;</font> event_handler
        <font face='Lucida Console'>)</font>
        <b>{</b>
            auto_mutex <font color='#BB00BB'>M</font><font face='Lucida Console'>(</font>m<font face='Lucida Console'>)</font>;
            enter_key_handler <font color='#5555FF'>=</font> event_handler;
        <b>}</b>

        <font color='#0000FF'>template</font> <font color='#5555FF'>&lt;</font>
            <font color='#0000FF'>typename</font> T
            <font color='#5555FF'>&gt;</font>
        <font color='#0000FF'><u>void</u></font> <b><a name='set_focus_lost_handler'></a>set_focus_lost_handler</b> <font face='Lucida Console'>(</font>
            T<font color='#5555FF'>&amp;</font> object,
            <font color='#0000FF'><u>void</u></font> <font face='Lucida Console'>(</font>T::<font color='#5555FF'>*</font>event_handler<font face='Lucida Console'>)</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>
        <font face='Lucida Console'>)</font>
        <b>{</b>
            auto_mutex <font color='#BB00BB'>M</font><font face='Lucida Console'>(</font>m<font face='Lucida Console'>)</font>;
            focus_lost_handler <font color='#5555FF'>=</font> <font color='#BB00BB'>make_mfp</font><font face='Lucida Console'>(</font>object,event_handler<font face='Lucida Console'>)</font>;
        <b>}</b>

        <font color='#0000FF'><u>void</u></font> <b><a name='set_focus_lost_handler'></a>set_focus_lost_handler</b> <font face='Lucida Console'>(</font>
            <font color='#0000FF'>const</font> any_function<font color='#5555FF'>&lt;</font><font color='#0000FF'><u>void</u></font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>&gt;</font><font color='#5555FF'>&amp;</font> event_handler
        <font face='Lucida Console'>)</font>
        <b>{</b>
            auto_mutex <font color='#BB00BB'>M</font><font face='Lucida Console'>(</font>m<font face='Lucida Console'>)</font>;
            focus_lost_handler <font color='#5555FF'>=</font> event_handler;
        <b>}</b>

    <font color='#0000FF'>private</font>:

        <font color='#0000FF'><u>void</u></font> <b><a name='on_cut'></a>on_cut</b> <font face='Lucida Console'>(</font>
        <font face='Lucida Console'>)</font>;
        
        <font color='#0000FF'><u>void</u></font> <b><a name='on_copy'></a>on_copy</b> <font face='Lucida Console'>(</font>
        <font face='Lucida Console'>)</font>;

        <font color='#0000FF'><u>void</u></font> <b><a name='on_paste'></a>on_paste</b> <font face='Lucida Console'>(</font>
        <font face='Lucida Console'>)</font>;

        <font color='#0000FF'><u>void</u></font> <b><a name='on_select_all'></a>on_select_all</b> <font face='Lucida Console'>(</font>
        <font face='Lucida Console'>)</font>;

        <font color='#0000FF'><u>void</u></font> <b><a name='on_delete_selected'></a>on_delete_selected</b> <font face='Lucida Console'>(</font>
        <font face='Lucida Console'>)</font>;

        <font color='#0000FF'><u>void</u></font> <b><a name='on_text_is_selected'></a>on_text_is_selected</b> <font face='Lucida Console'>(</font>
        <font face='Lucida Console'>)</font>;

        <font color='#0000FF'><u>void</u></font> <b><a name='on_no_text_selected'></a>on_no_text_selected</b> <font face='Lucida Console'>(</font>
        <font face='Lucida Console'>)</font>;

        <font color='#0000FF'><u>void</u></font> <b><a name='on_user_event'></a>on_user_event</b> <font face='Lucida Console'>(</font>
            <font color='#0000FF'><u>int</u></font> num
        <font face='Lucida Console'>)</font>
        <b>{</b>
            <font color='#009900'>// ignore this user event if it isn't for us
</font>            <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>num <font color='#5555FF'>!</font><font color='#5555FF'>=</font> drawable::<font color='#BB00BB'>next_free_user_event_number</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>
                <font color='#0000FF'>return</font>;

            <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>recent_movement <font color='#5555FF'>=</font><font color='#5555FF'>=</font> <font color='#979000'>false</font><font face='Lucida Console'>)</font>
            <b>{</b>
                cursor_visible <font color='#5555FF'>=</font> <font color='#5555FF'>!</font>cursor_visible; 
                parent.<font color='#BB00BB'>invalidate_rectangle</font><font face='Lucida Console'>(</font>rect<font face='Lucida Console'>)</font>; 
            <b>}</b>
            <font color='#0000FF'>else</font>
            <b>{</b>
                <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>cursor_visible <font color='#5555FF'>=</font><font color='#5555FF'>=</font> <font color='#979000'>false</font><font face='Lucida Console'>)</font>
                <b>{</b>
                    cursor_visible <font color='#5555FF'>=</font> <font color='#979000'>true</font>;
                    parent.<font color='#BB00BB'>invalidate_rectangle</font><font face='Lucida Console'>(</font>rect<font face='Lucida Console'>)</font>; 
                <b>}</b>
                recent_movement <font color='#5555FF'>=</font> <font color='#979000'>false</font>;
            <b>}</b>
        <b>}</b>

        <font color='#0000FF'><u>void</u></font> <b><a name='timer_action'></a>timer_action</b> <font face='Lucida Console'>(</font>
        <font face='Lucida Console'>)</font> <b>{</b> parent.<font color='#BB00BB'>trigger_user_event</font><font face='Lucida Console'>(</font><font color='#0000FF'>this</font>,drawable::<font color='#BB00BB'>next_free_user_event_number</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>; <b>}</b>
        <font color='#009900'>/*!
            ensures
                - flips the state of cursor_visible
        !*/</font>

        <font color='#0000FF'><u>void</u></font> <b><a name='move_cursor'></a>move_cursor</b> <font face='Lucida Console'>(</font>
            <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> pos
        <font face='Lucida Console'>)</font>;
        <font color='#009900'>/*!
            requires
                - pos &lt;= text_.size() 
            ensures
                - moves the cursor to the position given by pos and moves the text 
                  in the text box if necessary
                - if the position changes then the parent window will be updated
        !*/</font>

        rectangle <b><a name='get_text_rect'></a>get_text_rect</b> <font face='Lucida Console'>(</font>
        <font face='Lucida Console'>)</font> <font color='#0000FF'>const</font>;
        <font color='#009900'>/*!
            ensures
                - returns the rectangle that should contain the text in this widget
        !*/</font>

        dlib::ustring text_;
        rgb_pixel text_color_;
        rgb_pixel bg_color_;

        <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> text_width;
        <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> text_pos;


        <font color='#0000FF'><u>bool</u></font> recent_movement;
        <font color='#0000FF'><u>bool</u></font> has_focus;
        <font color='#0000FF'><u>bool</u></font> cursor_visible;
        <font color='#0000FF'><u>long</u></font> cursor_pos;
        <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> cursor_x;

        <font color='#009900'>// this tells you what part of the text is highlighted
</font>        <font color='#0000FF'><u>long</u></font> highlight_start;
        <font color='#0000FF'><u>long</u></font> highlight_end;
        <font color='#0000FF'><u>long</u></font> shift_pos;
        any_function<font color='#5555FF'>&lt;</font><font color='#0000FF'><u>void</u></font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>&gt;</font> text_modified_handler;
        any_function<font color='#5555FF'>&lt;</font><font color='#0000FF'><u>void</u></font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>&gt;</font> enter_key_handler;
        any_function<font color='#5555FF'>&lt;</font><font color='#0000FF'><u>void</u></font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>&gt;</font> focus_lost_handler;

        scoped_ptr<font color='#5555FF'>&lt;</font>text_field_style<font color='#5555FF'>&gt;</font> style;

        timer<font color='#5555FF'>&lt;</font>text_field<font color='#5555FF'>&gt;</font> t;

        popup_menu_region right_click_menu;

        <font color='#009900'>// restricted functions
</font>        <b><a name='text_field'></a>text_field</b><font face='Lucida Console'>(</font>text_field<font color='#5555FF'>&amp;</font><font face='Lucida Console'>)</font>;        <font color='#009900'>// copy constructor
</font>        text_field<font color='#5555FF'>&amp;</font> <b><a name='operator'></a>operator</b><font color='#5555FF'>=</font><font face='Lucida Console'>(</font>text_field<font color='#5555FF'>&amp;</font><font face='Lucida Console'>)</font>;    <font color='#009900'>// assignment operator
</font>

    <font color='#0000FF'>protected</font>:

        <font color='#0000FF'><u>void</u></font> <b><a name='draw'></a>draw</b> <font face='Lucida Console'>(</font>
            <font color='#0000FF'>const</font> canvas<font color='#5555FF'>&amp;</font> c
        <font face='Lucida Console'>)</font> <font color='#0000FF'>const</font>;


        <font color='#0000FF'><u>void</u></font> <b><a name='on_mouse_down'></a>on_mouse_down</b> <font face='Lucida Console'>(</font>
            <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> btn,
            <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> state,
            <font color='#0000FF'><u>long</u></font> x,
            <font color='#0000FF'><u>long</u></font> y,
            <font color='#0000FF'><u>bool</u></font> is_double_click
        <font face='Lucida Console'>)</font>;

        <font color='#0000FF'><u>void</u></font> <b><a name='on_mouse_up'></a>on_mouse_up</b> <font face='Lucida Console'>(</font>
            <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> btn,
            <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> state,
            <font color='#0000FF'><u>long</u></font> x,
            <font color='#0000FF'><u>long</u></font> y
        <font face='Lucida Console'>)</font>;

        <font color='#0000FF'><u>void</u></font> <b><a name='on_mouse_move'></a>on_mouse_move</b> <font face='Lucida Console'>(</font>
            <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> state,
            <font color='#0000FF'><u>long</u></font> x,
            <font color='#0000FF'><u>long</u></font> y
        <font face='Lucida Console'>)</font>;

        <font color='#0000FF'><u>void</u></font> <b><a name='on_keydown'></a>on_keydown</b> <font face='Lucida Console'>(</font>
            <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> key,
            <font color='#0000FF'><u>bool</u></font> is_printable,
            <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> state
        <font face='Lucida Console'>)</font>;

        <font color='#0000FF'><u>void</u></font> <b><a name='on_string_put'></a>on_string_put</b> <font face='Lucida Console'>(</font>
            <font color='#0000FF'>const</font> std::wstring <font color='#5555FF'>&amp;</font>str
        <font face='Lucida Console'>)</font>;
    <b>}</b>;

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font><font color='#009900'>// ----------------------------------------------------------------------------------------
</font>    <font color='#009900'>// class text_box
</font><font color='#009900'>// ----------------------------------------------------------------------------------------
</font><font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'>class</font> <b><a name='text_box'></a>text_box</b> : <font color='#0000FF'>public</font> scrollable_region
    <b>{</b>
        <font color='#009900'>/*!
            INITIAL VALUE
                text_color_ == rgb_pixel(0,0,0)
                bg_color_ == rgb_pixel(255,255,255)
                cursor_pos == 0
                text_ == ""
                has_focus == false
                cursor_visible == false
                recent_movement == false
                highlight_start == 0
                highlight_end == -1
                shift_pos == -1
    
            CONVENTION
                - cursor_pos == the position of the cursor in the string text_.  The 
                  cursor appears before the letter text_[cursor_pos]
                - cursor_rect == The rectangle that should be drawn for the cursor. 
                  The position is relative to total_rect().
                - has_focus == true if this text field has keyboard input focus
                - cursor_visible == true if the cursor should be painted
                - text_ == text()

                - if (has_focus &amp;&amp; the user has recently moved the cursor) then
                    - recent_movement == true
                - else
                    - recent_movement == false

                - if (highlight_start &lt;= highlight_end) then
                    - text[highlight_start] though text[highlight_end] should be
                      highlighted

                - if (shift_pos != -1) then
                    - has_focus == true
                    - the shift key is being held down or the left mouse button is
                      being held down.
                    - shift_pos == the position of the cursor when the shift or mouse key
                      was first pressed.

                - text_color() == text_color_
                - background_color() == bg_color_
        !*/</font>

    <font color='#0000FF'>public</font>:
        <b><a name='text_box'></a>text_box</b><font face='Lucida Console'>(</font>
            drawable_window<font color='#5555FF'>&amp;</font> w
        <font face='Lucida Console'>)</font> : 
            scrollable_region<font face='Lucida Console'>(</font>w,MOUSE_CLICK <font color='#5555FF'>|</font> KEYBOARD_EVENTS <font color='#5555FF'>|</font> MOUSE_MOVE <font color='#5555FF'>|</font> STRING_PUT<font face='Lucida Console'>)</font>,
            text_color_<font face='Lucida Console'>(</font><font color='#979000'>0</font>,<font color='#979000'>0</font>,<font color='#979000'>0</font><font face='Lucida Console'>)</font>,
            bg_color_<font face='Lucida Console'>(</font><font color='#979000'>255</font>,<font color='#979000'>255</font>,<font color='#979000'>255</font><font face='Lucida Console'>)</font>,
            recent_movement<font face='Lucida Console'>(</font><font color='#979000'>false</font><font face='Lucida Console'>)</font>,
            has_focus<font face='Lucida Console'>(</font><font color='#979000'>false</font><font face='Lucida Console'>)</font>,
            cursor_visible<font face='Lucida Console'>(</font><font color='#979000'>false</font><font face='Lucida Console'>)</font>,
            cursor_pos<font face='Lucida Console'>(</font><font color='#979000'>0</font><font face='Lucida Console'>)</font>,
            highlight_start<font face='Lucida Console'>(</font><font color='#979000'>0</font><font face='Lucida Console'>)</font>,
            highlight_end<font face='Lucida Console'>(</font><font color='#5555FF'>-</font><font color='#979000'>1</font><font face='Lucida Console'>)</font>,
            shift_pos<font face='Lucida Console'>(</font><font color='#5555FF'>-</font><font color='#979000'>1</font><font face='Lucida Console'>)</font>,
            t<font face='Lucida Console'>(</font><font color='#5555FF'>*</font><font color='#0000FF'>this</font>,<font color='#5555FF'>&amp;</font>text_box::timer_action<font face='Lucida Console'>)</font>,
            right_click_menu<font face='Lucida Console'>(</font>w<font face='Lucida Console'>)</font>
        <b>{</b>
            style.<font color='#BB00BB'>reset</font><font face='Lucida Console'>(</font><font color='#0000FF'>new</font> <font color='#BB00BB'>text_box_style_default</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;

            <font color='#0000FF'>const</font> <font color='#0000FF'><u>long</u></font> padding <font color='#5555FF'>=</font> <font color='#0000FF'>static_cast</font><font color='#5555FF'>&lt;</font><font color='#0000FF'><u>long</u></font><font color='#5555FF'>&gt;</font><font face='Lucida Console'>(</font>style<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font><font color='#BB00BB'>get_padding</font><font face='Lucida Console'>(</font><font color='#5555FF'>*</font>mfont<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
            cursor_rect <font color='#5555FF'>=</font> mfont<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font><font color='#BB00BB'>compute_cursor_rect</font><font face='Lucida Console'>(</font><font color='#BB00BB'>rectangle</font><font face='Lucida Console'>(</font>padding,padding,<font color='#979000'>1000000</font>,<font color='#979000'>1000000</font><font face='Lucida Console'>)</font>, text_, <font color='#979000'>0</font><font face='Lucida Console'>)</font>;

            <font color='#BB00BB'>adjust_total_rect</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;

            <font color='#BB00BB'>set_vertical_mouse_wheel_scroll_increment</font><font face='Lucida Console'>(</font>mfont<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font><font color='#BB00BB'>height</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
            <font color='#BB00BB'>set_horizontal_mouse_wheel_scroll_increment</font><font face='Lucida Console'>(</font>mfont<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font><font color='#BB00BB'>height</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;

            right_click_menu.<font color='#BB00BB'>menu</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>.<font color='#BB00BB'>add_menu_item</font><font face='Lucida Console'>(</font><font color='#BB00BB'>menu_item_text</font><font face='Lucida Console'>(</font>"<font color='#CC0000'>Cut</font>",<font color='#5555FF'>*</font><font color='#0000FF'>this</font>,<font color='#5555FF'>&amp;</font>text_box::on_cut,'<font color='#FF0000'>t</font>'<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
            right_click_menu.<font color='#BB00BB'>menu</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>.<font color='#BB00BB'>add_menu_item</font><font face='Lucida Console'>(</font><font color='#BB00BB'>menu_item_text</font><font face='Lucida Console'>(</font>"<font color='#CC0000'>Copy</font>",<font color='#5555FF'>*</font><font color='#0000FF'>this</font>,<font color='#5555FF'>&amp;</font>text_box::on_copy,'<font color='#FF0000'>C</font>'<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
            right_click_menu.<font color='#BB00BB'>menu</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>.<font color='#BB00BB'>add_menu_item</font><font face='Lucida Console'>(</font><font color='#BB00BB'>menu_item_text</font><font face='Lucida Console'>(</font>"<font color='#CC0000'>Paste</font>",<font color='#5555FF'>*</font><font color='#0000FF'>this</font>,<font color='#5555FF'>&amp;</font>text_box::on_paste,'<font color='#FF0000'>P</font>'<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
            right_click_menu.<font color='#BB00BB'>menu</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>.<font color='#BB00BB'>add_menu_item</font><font face='Lucida Console'>(</font><font color='#BB00BB'>menu_item_text</font><font face='Lucida Console'>(</font>"<font color='#CC0000'>Delete</font>",<font color='#5555FF'>*</font><font color='#0000FF'>this</font>,<font color='#5555FF'>&amp;</font>text_box::on_delete_selected,'<font color='#FF0000'>D</font>'<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
            right_click_menu.<font color='#BB00BB'>menu</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>.<font color='#BB00BB'>add_menu_item</font><font face='Lucida Console'>(</font><font color='#BB00BB'>menu_item_separator</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
            right_click_menu.<font color='#BB00BB'>menu</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>.<font color='#BB00BB'>add_menu_item</font><font face='Lucida Console'>(</font><font color='#BB00BB'>menu_item_text</font><font face='Lucida Console'>(</font>"<font color='#CC0000'>Select All</font>",<font color='#5555FF'>*</font><font color='#0000FF'>this</font>,<font color='#5555FF'>&amp;</font>text_box::on_select_all,'<font color='#FF0000'>A</font>'<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;

            right_click_menu.<font color='#BB00BB'>set_rect</font><font face='Lucida Console'>(</font><font color='#BB00BB'>get_text_rect</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;

            <font color='#BB00BB'>set_size</font><font face='Lucida Console'>(</font><font color='#979000'>100</font>,<font color='#979000'>100</font><font face='Lucida Console'>)</font>;

            <font color='#BB00BB'>enable_events</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;

            t.<font color='#BB00BB'>set_delay_time</font><font face='Lucida Console'>(</font><font color='#979000'>500</font><font face='Lucida Console'>)</font>;
        <b>}</b>

        ~<b><a name='text_box'></a>text_box</b> <font face='Lucida Console'>(</font>
        <font face='Lucida Console'>)</font>
        <b>{</b>
            <font color='#BB00BB'>disable_events</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
            parent.<font color='#BB00BB'>invalidate_rectangle</font><font face='Lucida Console'>(</font>rect<font face='Lucida Console'>)</font>; 
            t.<font color='#BB00BB'>stop_and_wait</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
        <b>}</b>

        <font color='#0000FF'>template</font> <font color='#5555FF'>&lt;</font>
            <font color='#0000FF'>typename</font> style_type
            <font color='#5555FF'>&gt;</font>
        <font color='#0000FF'><u>void</u></font> <b><a name='set_style'></a>set_style</b> <font face='Lucida Console'>(</font>
            <font color='#0000FF'>const</font> style_type<font color='#5555FF'>&amp;</font> style_
        <font face='Lucida Console'>)</font>
        <b>{</b>
            auto_mutex <font color='#BB00BB'>M</font><font face='Lucida Console'>(</font>m<font face='Lucida Console'>)</font>;
            style.<font color='#BB00BB'>reset</font><font face='Lucida Console'>(</font><font color='#0000FF'>new</font> <font color='#BB00BB'>style_type</font><font face='Lucida Console'>(</font>style_<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;

            scrollable_region::<font color='#BB00BB'>set_style</font><font face='Lucida Console'>(</font>style_.<font color='#BB00BB'>get_scrollable_region_style</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
            <font color='#009900'>// call this just so that this widget redraws itself with the new style
</font>            <font color='#BB00BB'>set_main_font</font><font face='Lucida Console'>(</font>mfont<font face='Lucida Console'>)</font>;
        <b>}</b>

        <font color='#0000FF'><u>void</u></font> <b><a name='set_text'></a>set_text</b> <font face='Lucida Console'>(</font>
            <font color='#0000FF'>const</font> std::string<font color='#5555FF'>&amp;</font> text_
        <font face='Lucida Console'>)</font>;

        <font color='#0000FF'><u>void</u></font> <b><a name='set_text'></a>set_text</b> <font face='Lucida Console'>(</font>
            <font color='#0000FF'>const</font> std::wstring<font color='#5555FF'>&amp;</font> text_
        <font face='Lucida Console'>)</font>;

        <font color='#0000FF'><u>void</u></font> <b><a name='set_text'></a>set_text</b> <font face='Lucida Console'>(</font>
            <font color='#0000FF'>const</font> dlib::ustring<font color='#5555FF'>&amp;</font> text_
        <font face='Lucida Console'>)</font>;

        <font color='#0000FF'>const</font> std::string <b><a name='text'></a>text</b> <font face='Lucida Console'>(</font>
        <font face='Lucida Console'>)</font> <font color='#0000FF'>const</font>;

        <font color='#0000FF'>const</font> std::wstring <b><a name='wtext'></a>wtext</b> <font face='Lucida Console'>(</font>
        <font face='Lucida Console'>)</font> <font color='#0000FF'>const</font>;

        <font color='#0000FF'>const</font> dlib::ustring <b><a name='utext'></a>utext</b> <font face='Lucida Console'>(</font>
        <font face='Lucida Console'>)</font> <font color='#0000FF'>const</font>;

        <font color='#0000FF'><u>void</u></font> <b><a name='set_text_color'></a>set_text_color</b> <font face='Lucida Console'>(</font>
            <font color='#0000FF'>const</font> rgb_pixel color
        <font face='Lucida Console'>)</font>;

        <font color='#0000FF'>const</font> rgb_pixel <b><a name='text_color'></a>text_color</b> <font face='Lucida Console'>(</font>
        <font face='Lucida Console'>)</font> <font color='#0000FF'>const</font>;

        <font color='#0000FF'><u>void</u></font> <b><a name='set_background_color'></a>set_background_color</b> <font face='Lucida Console'>(</font>
            <font color='#0000FF'>const</font> rgb_pixel color
        <font face='Lucida Console'>)</font>;

        <font color='#0000FF'>const</font> rgb_pixel <b><a name='background_color'></a>background_color</b> <font face='Lucida Console'>(</font>
        <font face='Lucida Console'>)</font> <font color='#0000FF'>const</font>;

        <font color='#0000FF'><u>void</u></font> <b><a name='set_size'></a>set_size</b> <font face='Lucida Console'>(</font>
            <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> width,
            <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> height 
        <font face='Lucida Console'>)</font>;

        <font color='#0000FF'><u>void</u></font> <b><a name='set_pos'></a>set_pos</b> <font face='Lucida Console'>(</font>
            <font color='#0000FF'><u>long</u></font> x,
            <font color='#0000FF'><u>long</u></font> y
        <font face='Lucida Console'>)</font>;

        <font color='#0000FF'><u>void</u></font> <b><a name='set_main_font'></a>set_main_font</b> <font face='Lucida Console'>(</font>
            <font color='#0000FF'>const</font> shared_ptr_thread_safe<font color='#5555FF'>&lt;</font>font<font color='#5555FF'>&gt;</font><font color='#5555FF'>&amp;</font> f
        <font face='Lucida Console'>)</font>;

        <font color='#0000FF'><u>int</u></font> <b><a name='next_free_user_event_number'></a>next_free_user_event_number</b> <font face='Lucida Console'>(</font>
        <font face='Lucida Console'>)</font> <font color='#0000FF'>const</font>
        <b>{</b>
            <font color='#0000FF'>return</font> scrollable_region::<font color='#BB00BB'>next_free_user_event_number</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>+</font><font color='#979000'>1</font>;
        <b>}</b>

        <font color='#0000FF'><u>void</u></font> <b><a name='disable'></a>disable</b> <font face='Lucida Console'>(</font>
        <font face='Lucida Console'>)</font>;

        <font color='#0000FF'><u>void</u></font> <b><a name='enable'></a>enable</b> <font face='Lucida Console'>(</font>
        <font face='Lucida Console'>)</font>;

        <font color='#0000FF'><u>void</u></font> <b><a name='hide'></a>hide</b> <font face='Lucida Console'>(</font>
        <font face='Lucida Console'>)</font>;

        <font color='#0000FF'><u>void</u></font> <b><a name='show'></a>show</b> <font face='Lucida Console'>(</font>
        <font face='Lucida Console'>)</font>;

        <font color='#0000FF'>template</font> <font color='#5555FF'>&lt;</font>
            <font color='#0000FF'>typename</font> T
            <font color='#5555FF'>&gt;</font>
        <font color='#0000FF'><u>void</u></font> <b><a name='set_text_modified_handler'></a>set_text_modified_handler</b> <font face='Lucida Console'>(</font>
            T<font color='#5555FF'>&amp;</font> object,
            <font color='#0000FF'><u>void</u></font> <font face='Lucida Console'>(</font>T::<font color='#5555FF'>*</font>event_handler<font face='Lucida Console'>)</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>
        <font face='Lucida Console'>)</font>
        <b>{</b>
            auto_mutex <font color='#BB00BB'>M</font><font face='Lucida Console'>(</font>m<font face='Lucida Console'>)</font>;
            text_modified_handler <font color='#5555FF'>=</font> <font color='#BB00BB'>make_mfp</font><font face='Lucida Console'>(</font>object,event_handler<font face='Lucida Console'>)</font>;
        <b>}</b>

        <font color='#0000FF'><u>void</u></font> <b><a name='set_text_modified_handler'></a>set_text_modified_handler</b> <font face='Lucida Console'>(</font>
            <font color='#0000FF'>const</font> any_function<font color='#5555FF'>&lt;</font><font color='#0000FF'><u>void</u></font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>&gt;</font><font color='#5555FF'>&amp;</font> event_handler
        <font face='Lucida Console'>)</font>
        <b>{</b>
            auto_mutex <font color='#BB00BB'>M</font><font face='Lucida Console'>(</font>m<font face='Lucida Console'>)</font>;
            text_modified_handler <font color='#5555FF'>=</font> event_handler;
        <b>}</b>

        <font color='#0000FF'>template</font> <font color='#5555FF'>&lt;</font>
            <font color='#0000FF'>typename</font> T
            <font color='#5555FF'>&gt;</font>
        <font color='#0000FF'><u>void</u></font> <b><a name='set_enter_key_handler'></a>set_enter_key_handler</b> <font face='Lucida Console'>(</font>
            T<font color='#5555FF'>&amp;</font> object,
            <font color='#0000FF'><u>void</u></font> <font face='Lucida Console'>(</font>T::<font color='#5555FF'>*</font>event_handler<font face='Lucida Console'>)</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>
        <font face='Lucida Console'>)</font>
        <b>{</b>
            auto_mutex <font color='#BB00BB'>M</font><font face='Lucida Console'>(</font>m<font face='Lucida Console'>)</font>;
            enter_key_handler <font color='#5555FF'>=</font> <font color='#BB00BB'>make_mfp</font><font face='Lucida Console'>(</font>object,event_handler<font face='Lucida Console'>)</font>;
        <b>}</b>

        <font color='#0000FF'><u>void</u></font> <b><a name='set_enter_key_handler'></a>set_enter_key_handler</b> <font face='Lucida Console'>(</font>
            <font color='#0000FF'>const</font> any_function<font color='#5555FF'>&lt;</font><font color='#0000FF'><u>void</u></font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>&gt;</font><font color='#5555FF'>&amp;</font> event_handler
        <font face='Lucida Console'>)</font>
        <b>{</b>
            auto_mutex <font color='#BB00BB'>M</font><font face='Lucida Console'>(</font>m<font face='Lucida Console'>)</font>;
            enter_key_handler <font color='#5555FF'>=</font> event_handler;
        <b>}</b>

        <font color='#0000FF'>template</font> <font color='#5555FF'>&lt;</font>
            <font color='#0000FF'>typename</font> T
            <font color='#5555FF'>&gt;</font>
        <font color='#0000FF'><u>void</u></font> <b><a name='set_focus_lost_handler'></a>set_focus_lost_handler</b> <font face='Lucida Console'>(</font>
            T<font color='#5555FF'>&amp;</font> object,
            <font color='#0000FF'><u>void</u></font> <font face='Lucida Console'>(</font>T::<font color='#5555FF'>*</font>event_handler<font face='Lucida Console'>)</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>
        <font face='Lucida Console'>)</font>
        <b>{</b>
            auto_mutex <font color='#BB00BB'>M</font><font face='Lucida Console'>(</font>m<font face='Lucida Console'>)</font>;
            focus_lost_handler <font color='#5555FF'>=</font> <font color='#BB00BB'>make_mfp</font><font face='Lucida Console'>(</font>object,event_handler<font face='Lucida Console'>)</font>;
        <b>}</b>

        <font color='#0000FF'><u>void</u></font> <b><a name='set_focus_lost_handler'></a>set_focus_lost_handler</b> <font face='Lucida Console'>(</font>
            <font color='#0000FF'>const</font> any_function<font color='#5555FF'>&lt;</font><font color='#0000FF'><u>void</u></font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>&gt;</font><font color='#5555FF'>&amp;</font> event_handler
        <font face='Lucida Console'>)</font>
        <b>{</b>
            auto_mutex <font color='#BB00BB'>M</font><font face='Lucida Console'>(</font>m<font face='Lucida Console'>)</font>;
            focus_lost_handler <font color='#5555FF'>=</font> event_handler;
        <b>}</b>

    <font color='#0000FF'>private</font>:

        <font color='#0000FF'><u>void</u></font> <b><a name='on_cut'></a>on_cut</b> <font face='Lucida Console'>(</font>
        <font face='Lucida Console'>)</font>;
        
        <font color='#0000FF'><u>void</u></font> <b><a name='on_copy'></a>on_copy</b> <font face='Lucida Console'>(</font>
        <font face='Lucida Console'>)</font>;

        <font color='#0000FF'><u>void</u></font> <b><a name='on_paste'></a>on_paste</b> <font face='Lucida Console'>(</font>
        <font face='Lucida Console'>)</font>;

        <font color='#0000FF'><u>void</u></font> <b><a name='on_select_all'></a>on_select_all</b> <font face='Lucida Console'>(</font>
        <font face='Lucida Console'>)</font>;

        <font color='#0000FF'><u>void</u></font> <b><a name='on_delete_selected'></a>on_delete_selected</b> <font face='Lucida Console'>(</font>
        <font face='Lucida Console'>)</font>;

        <font color='#0000FF'><u>void</u></font> <b><a name='on_text_is_selected'></a>on_text_is_selected</b> <font face='Lucida Console'>(</font>
        <font face='Lucida Console'>)</font>;

        <font color='#0000FF'><u>void</u></font> <b><a name='on_no_text_selected'></a>on_no_text_selected</b> <font face='Lucida Console'>(</font>
        <font face='Lucida Console'>)</font>;

        <font color='#0000FF'><u>void</u></font> <b><a name='on_user_event'></a>on_user_event</b> <font face='Lucida Console'>(</font>
            <font color='#0000FF'><u>int</u></font> num
        <font face='Lucida Console'>)</font>
        <b>{</b>
            <font color='#009900'>// ignore this user event if it isn't for us
</font>            <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>num <font color='#5555FF'>!</font><font color='#5555FF'>=</font> scrollable_region::<font color='#BB00BB'>next_free_user_event_number</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>
                <font color='#0000FF'>return</font>;

            <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>recent_movement <font color='#5555FF'>=</font><font color='#5555FF'>=</font> <font color='#979000'>false</font><font face='Lucida Console'>)</font>
            <b>{</b>
                cursor_visible <font color='#5555FF'>=</font> <font color='#5555FF'>!</font>cursor_visible; 
                parent.<font color='#BB00BB'>invalidate_rectangle</font><font face='Lucida Console'>(</font>rect<font face='Lucida Console'>)</font>; 
            <b>}</b>
            <font color='#0000FF'>else</font>
            <b>{</b>
                <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>cursor_visible <font color='#5555FF'>=</font><font color='#5555FF'>=</font> <font color='#979000'>false</font><font face='Lucida Console'>)</font>
                <b>{</b>
                    cursor_visible <font color='#5555FF'>=</font> <font color='#979000'>true</font>;
                    parent.<font color='#BB00BB'>invalidate_rectangle</font><font face='Lucida Console'>(</font>rect<font face='Lucida Console'>)</font>; 
                <b>}</b>
                recent_movement <font color='#5555FF'>=</font> <font color='#979000'>false</font>;
            <b>}</b>
        <b>}</b>

        <font color='#009900'>// The reason for using user actions here rather than just having the timer just call
</font>        <font color='#009900'>// what it needs directly is to avoid a potential deadlock during destruction of this widget.
</font>        <font color='#0000FF'><u>void</u></font> <b><a name='timer_action'></a>timer_action</b> <font face='Lucida Console'>(</font>
        <font face='Lucida Console'>)</font> <b>{</b> parent.<font color='#BB00BB'>trigger_user_event</font><font face='Lucida Console'>(</font><font color='#0000FF'>this</font>,scrollable_region::<font color='#BB00BB'>next_free_user_event_number</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>; <b>}</b>
        <font color='#009900'>/*!
            ensures
                - flips the state of cursor_visible
        !*/</font>

        <font color='#0000FF'><u>void</u></font> <b><a name='move_cursor'></a>move_cursor</b> <font face='Lucida Console'>(</font>
            <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> pos
        <font face='Lucida Console'>)</font>;
        <font color='#009900'>/*!
            requires
                - pos &lt;= text_.size() 
            ensures
                - moves the cursor to the position given by pos and moves the text 
                  in the text box if necessary
                - if the position changes then the parent window will be updated
        !*/</font>

        rectangle <b><a name='get_text_rect'></a>get_text_rect</b> <font face='Lucida Console'>(</font>
        <font face='Lucida Console'>)</font> <font color='#0000FF'>const</font>;
        <font color='#009900'>/*!
            ensures
                - returns the rectangle that should contain the text in this widget
        !*/</font>

        <font color='#0000FF'><u>void</u></font> <b><a name='adjust_total_rect'></a>adjust_total_rect</b> <font face='Lucida Console'>(</font>
        <font face='Lucida Console'>)</font>;
        <font color='#009900'>/*!
            ensures
                - adjusts total_rect() so that it is big enough to contain the text
                  currently in this object.
        !*/</font>

        dlib::ustring text_;
        rgb_pixel text_color_;
        rgb_pixel bg_color_;



        <font color='#0000FF'><u>bool</u></font> recent_movement;
        <font color='#0000FF'><u>bool</u></font> has_focus;
        <font color='#0000FF'><u>bool</u></font> cursor_visible;
        <font color='#0000FF'><u>long</u></font> cursor_pos;
        rectangle cursor_rect;

        <font color='#009900'>// this tells you what part of the text is highlighted
</font>        <font color='#0000FF'><u>long</u></font> highlight_start;
        <font color='#0000FF'><u>long</u></font> highlight_end;
        <font color='#0000FF'><u>long</u></font> shift_pos;
        any_function<font color='#5555FF'>&lt;</font><font color='#0000FF'><u>void</u></font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>&gt;</font> text_modified_handler;
        any_function<font color='#5555FF'>&lt;</font><font color='#0000FF'><u>void</u></font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>&gt;</font> enter_key_handler;
        any_function<font color='#5555FF'>&lt;</font><font color='#0000FF'><u>void</u></font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>&gt;</font> focus_lost_handler;

        scoped_ptr<font color='#5555FF'>&lt;</font>text_box_style<font color='#5555FF'>&gt;</font> style;

        timer<font color='#5555FF'>&lt;</font>text_box<font color='#5555FF'>&gt;</font> t;

        popup_menu_region right_click_menu;

        <font color='#009900'>// restricted functions
</font>        <b><a name='text_box'></a>text_box</b><font face='Lucida Console'>(</font>text_box<font color='#5555FF'>&amp;</font><font face='Lucida Console'>)</font>;        <font color='#009900'>// copy constructor
</font>        text_box<font color='#5555FF'>&amp;</font> <b><a name='operator'></a>operator</b><font color='#5555FF'>=</font><font face='Lucida Console'>(</font>text_box<font color='#5555FF'>&amp;</font><font face='Lucida Console'>)</font>;    <font color='#009900'>// assignment operator
</font>

    <font color='#0000FF'>protected</font>:

        <font color='#0000FF'><u>void</u></font> <b><a name='draw'></a>draw</b> <font face='Lucida Console'>(</font>
            <font color='#0000FF'>const</font> canvas<font color='#5555FF'>&amp;</font> c
        <font face='Lucida Console'>)</font> <font color='#0000FF'>const</font>;


        <font color='#0000FF'><u>void</u></font> <b><a name='on_mouse_down'></a>on_mouse_down</b> <font face='Lucida Console'>(</font>
            <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> btn,
            <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> state,
            <font color='#0000FF'><u>long</u></font> x,
            <font color='#0000FF'><u>long</u></font> y,
            <font color='#0000FF'><u>bool</u></font> is_double_click
        <font face='Lucida Console'>)</font>;

        <font color='#0000FF'><u>void</u></font> <b><a name='on_mouse_up'></a>on_mouse_up</b> <font face='Lucida Console'>(</font>
            <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> btn,
            <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> state,
            <font color='#0000FF'><u>long</u></font> x,
            <font color='#0000FF'><u>long</u></font> y
        <font face='Lucida Console'>)</font>;

        <font color='#0000FF'><u>void</u></font> <b><a name='on_mouse_move'></a>on_mouse_move</b> <font face='Lucida Console'>(</font>
            <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> state,
            <font color='#0000FF'><u>long</u></font> x,
            <font color='#0000FF'><u>long</u></font> y
        <font face='Lucida Console'>)</font>;

        <font color='#0000FF'><u>void</u></font> <b><a name='on_keydown'></a>on_keydown</b> <font face='Lucida Console'>(</font>
            <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> key,
            <font color='#0000FF'><u>bool</u></font> is_printable,
            <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> state
        <font face='Lucida Console'>)</font>;

        <font color='#0000FF'><u>void</u></font> <b><a name='on_string_put'></a>on_string_put</b> <font face='Lucida Console'>(</font>
            <font color='#0000FF'>const</font> std::wstring <font color='#5555FF'>&amp;</font>str
        <font face='Lucida Console'>)</font>;
    <b>}</b>;

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font><font color='#009900'>// ----------------------------------------------------------------------------------------
</font>    <font color='#009900'>// class check_box
</font><font color='#009900'>// ----------------------------------------------------------------------------------------
</font><font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'>class</font> <b><a name='check_box'></a>check_box</b> : <font color='#0000FF'>public</font> toggle_button 
    <b>{</b>
    <font color='#0000FF'>public</font>:
        <b><a name='check_box'></a>check_box</b><font face='Lucida Console'>(</font>  
            drawable_window<font color='#5555FF'>&amp;</font> w
        <font face='Lucida Console'>)</font> : toggle_button<font face='Lucida Console'>(</font>w<font face='Lucida Console'>)</font>
        <b>{</b>
            <font color='#BB00BB'>set_style</font><font face='Lucida Console'>(</font><font color='#BB00BB'>toggle_button_style_check_box</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
        <b>}</b>

    <b>}</b>;

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font><font color='#009900'>// ----------------------------------------------------------------------------------------
</font>    <font color='#009900'>// class radio_button
</font><font color='#009900'>// ----------------------------------------------------------------------------------------
</font><font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'>class</font> <b><a name='radio_button'></a>radio_button</b> : <font color='#0000FF'>public</font> toggle_button 
    <b>{</b>
    <font color='#0000FF'>public</font>:
        <b><a name='radio_button'></a>radio_button</b> <font face='Lucida Console'>(</font>  
            drawable_window<font color='#5555FF'>&amp;</font> w
        <font face='Lucida Console'>)</font> : toggle_button<font face='Lucida Console'>(</font>w<font face='Lucida Console'>)</font>
        <b>{</b>
            <font color='#BB00BB'>set_style</font><font face='Lucida Console'>(</font><font color='#BB00BB'>toggle_button_style_radio_button</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
        <b>}</b>

    <b>}</b>;

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font><font color='#009900'>// ----------------------------------------------------------------------------------------
</font>    <font color='#009900'>// class tabbed_display
</font><font color='#009900'>// ----------------------------------------------------------------------------------------
</font><font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'>class</font> <b><a name='tabbed_display'></a>tabbed_display</b> : <font color='#0000FF'>public</font> drawable
    <b>{</b>
        <font color='#009900'>/*!
            INITIAL VALUE
                - tabs.size() == 0
                - selected_tab_ == 0

            CONVENTION
                - number_of_tabs() == tabs.size()
                - tab_name(idx) == tabs[idx]
                - if (tabs.size() &gt; 0) then
                    - selected_tab_ == the index of the tab that is currently selected

                - for all valid i:
                    - tabs[i].width == mfont-&gt;compute_size(tabs[i].name)
                    - tabs[i].rect == the rectangle that defines where this tab is
                    - if (tabs[i].group != 0) then
                        - tabs[i].group == a pointer to the widget_group for this tab.

                - left_pad == the amount of padding in a tab to the left of the name string.
                - right_pad == the amount of padding in a tab to the right of the name string.
                - top_pad == the amount of padding in a tab to the top of the name string.
                - bottom_pad == the amount of padding in a tab to the bottom of the name string.

                - if (event_handler.is_set()) then
                    - event_handler() is what is called to process click events
                      on this object.
        !*/</font>

    <font color='#0000FF'>public</font>:

        <b><a name='tabbed_display'></a>tabbed_display</b><font face='Lucida Console'>(</font>  
            drawable_window<font color='#5555FF'>&amp;</font> w
        <font face='Lucida Console'>)</font>;

        <font color='#0000FF'>virtual</font> ~<b><a name='tabbed_display'></a>tabbed_display</b><font face='Lucida Console'>(</font>
        <font face='Lucida Console'>)</font>;

        <font color='#0000FF'><u>void</u></font> <b><a name='set_size'></a>set_size</b> <font face='Lucida Console'>(</font>
            <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> width,
            <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> height
        <font face='Lucida Console'>)</font>;

        <font color='#0000FF'><u>void</u></font> <b><a name='set_number_of_tabs'></a>set_number_of_tabs</b> <font face='Lucida Console'>(</font>
            <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> num
        <font face='Lucida Console'>)</font>;

        <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> <b><a name='number_of_tabs'></a>number_of_tabs</b> <font face='Lucida Console'>(</font>
        <font face='Lucida Console'>)</font> <font color='#0000FF'>const</font>;

        <font color='#0000FF'>const</font> std::string <b><a name='tab_name'></a>tab_name</b> <font face='Lucida Console'>(</font>
            <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> idx
        <font face='Lucida Console'>)</font> <font color='#0000FF'>const</font>;

        <font color='#0000FF'>const</font> std::wstring <b><a name='tab_wname'></a>tab_wname</b> <font face='Lucida Console'>(</font>
            <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> idx
        <font face='Lucida Console'>)</font> <font color='#0000FF'>const</font>;

        <font color='#0000FF'>const</font> dlib::ustring<font color='#5555FF'>&amp;</font> <b><a name='tab_uname'></a>tab_uname</b> <font face='Lucida Console'>(</font>
            <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> idx
        <font face='Lucida Console'>)</font> <font color='#0000FF'>const</font>;

        <font color='#0000FF'><u>void</u></font> <b><a name='set_tab_name'></a>set_tab_name</b> <font face='Lucida Console'>(</font>
            <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> idx,
            <font color='#0000FF'>const</font> std::string<font color='#5555FF'>&amp;</font> new_name
        <font face='Lucida Console'>)</font>;

        <font color='#0000FF'><u>void</u></font> <b><a name='set_tab_name'></a>set_tab_name</b> <font face='Lucida Console'>(</font>
            <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> idx,
            <font color='#0000FF'>const</font> std::wstring<font color='#5555FF'>&amp;</font> new_name
        <font face='Lucida Console'>)</font>;

        <font color='#0000FF'><u>void</u></font> <b><a name='set_tab_name'></a>set_tab_name</b> <font face='Lucida Console'>(</font>
            <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> idx,
            <font color='#0000FF'>const</font> dlib::ustring<font color='#5555FF'>&amp;</font> new_name
        <font face='Lucida Console'>)</font>;

        <font color='#0000FF'><u>void</u></font> <b><a name='set_pos'></a>set_pos</b> <font face='Lucida Console'>(</font>
            <font color='#0000FF'><u>long</u></font> x,
            <font color='#0000FF'><u>long</u></font> y
        <font face='Lucida Console'>)</font>;

        <font color='#0000FF'>template</font> <font color='#5555FF'>&lt;</font>
            <font color='#0000FF'>typename</font> T
            <font color='#5555FF'>&gt;</font>
        <font color='#0000FF'><u>void</u></font> <b><a name='set_click_handler'></a>set_click_handler</b> <font face='Lucida Console'>(</font>
            T<font color='#5555FF'>&amp;</font> object,
            <font color='#0000FF'><u>void</u></font> <font face='Lucida Console'>(</font>T::<font color='#5555FF'>*</font>eh<font face='Lucida Console'>)</font><font face='Lucida Console'>(</font><font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> new_idx,<font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> old_idx<font face='Lucida Console'>)</font>
        <font face='Lucida Console'>)</font>
        <b>{</b>
            auto_mutex <font color='#BB00BB'>M</font><font face='Lucida Console'>(</font>m<font face='Lucida Console'>)</font>;
            event_handler <font color='#5555FF'>=</font> <font color='#BB00BB'>make_mfp</font><font face='Lucida Console'>(</font>object,eh<font face='Lucida Console'>)</font>;
        <b>}</b>

        <font color='#0000FF'><u>void</u></font> <b><a name='set_click_handler'></a>set_click_handler</b> <font face='Lucida Console'>(</font>
            <font color='#0000FF'>const</font> any_function<font color='#5555FF'>&lt;</font><font color='#0000FF'><u>void</u></font><font face='Lucida Console'>(</font><font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font>,<font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font><font face='Lucida Console'>)</font><font color='#5555FF'>&gt;</font><font color='#5555FF'>&amp;</font> eh
        <font face='Lucida Console'>)</font>
        <b>{</b>
            auto_mutex <font color='#BB00BB'>M</font><font face='Lucida Console'>(</font>m<font face='Lucida Console'>)</font>;
            event_handler <font color='#5555FF'>=</font> eh;
        <b>}</b>

        <font color='#0000FF'><u>void</u></font> <b><a name='set_tab_group'></a>set_tab_group</b> <font face='Lucida Console'>(</font>
            <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> idx,
            widget_group<font color='#5555FF'>&amp;</font> group
        <font face='Lucida Console'>)</font>;

        <font color='#0000FF'><u>void</u></font> <b><a name='show'></a>show</b> <font face='Lucida Console'>(</font>
        <font face='Lucida Console'>)</font>;

        <font color='#0000FF'><u>void</u></font> <b><a name='hide'></a>hide</b> <font face='Lucida Console'>(</font>
        <font face='Lucida Console'>)</font>;

        <font color='#0000FF'><u>void</u></font> <b><a name='enable'></a>enable</b> <font face='Lucida Console'>(</font>
        <font face='Lucida Console'>)</font>;

        <font color='#0000FF'><u>void</u></font> <b><a name='disable'></a>disable</b> <font face='Lucida Console'>(</font>
        <font face='Lucida Console'>)</font>;

        <font color='#0000FF'><u>void</u></font> <b><a name='set_main_font'></a>set_main_font</b> <font face='Lucida Console'>(</font>
            <font color='#0000FF'>const</font> shared_ptr_thread_safe<font color='#5555FF'>&lt;</font>font<font color='#5555FF'>&gt;</font><font color='#5555FF'>&amp;</font> f
        <font face='Lucida Console'>)</font>;

        <font color='#0000FF'><u>void</u></font> <b><a name='fit_to_contents'></a>fit_to_contents</b> <font face='Lucida Console'>(</font>
        <font face='Lucida Console'>)</font>;

    <font color='#0000FF'>protected</font>:
        <font color='#0000FF'><u>void</u></font> <b><a name='on_mouse_down'></a>on_mouse_down</b> <font face='Lucida Console'>(</font>
            <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> btn,
            <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> state,
            <font color='#0000FF'><u>long</u></font> x,
            <font color='#0000FF'><u>long</u></font> y,
            <font color='#0000FF'><u>bool</u></font> is_double_click
        <font face='Lucida Console'>)</font>;

        <font color='#0000FF'><u>void</u></font> <b><a name='draw'></a>draw</b> <font face='Lucida Console'>(</font>
            <font color='#0000FF'>const</font> canvas<font color='#5555FF'>&amp;</font> c
        <font face='Lucida Console'>)</font> <font color='#0000FF'>const</font>;

    <font color='#0000FF'>private</font>:
        <font color='#0000FF'><u>void</u></font> <b><a name='recompute_tabs'></a>recompute_tabs</b> <font face='Lucida Console'>(</font>
        <font face='Lucida Console'>)</font>;
        <font color='#009900'>/*!
            ensures
                - recomputes the rectangles for all the tabs and makes this object
                  wider if needed
        !*/</font>

        <font color='#0000FF'><u>void</u></font> <b><a name='draw_tab'></a>draw_tab</b> <font face='Lucida Console'>(</font>
            <font color='#0000FF'>const</font> rectangle<font color='#5555FF'>&amp;</font> tab,
            <font color='#0000FF'>const</font> canvas<font color='#5555FF'>&amp;</font> c
        <font face='Lucida Console'>)</font> <font color='#0000FF'>const</font>;
        <font color='#009900'>/*!
            ensures
                - draws the outline of a tab as given by the rectangle onto c
        !*/</font>

        <font color='#0000FF'>struct</font> <b><a name='tab_data'></a>tab_data</b>
        <b>{</b>
            <b><a name='tab_data'></a>tab_data</b><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> : width<font face='Lucida Console'>(</font><font color='#979000'>0</font><font face='Lucida Console'>)</font>, group<font face='Lucida Console'>(</font><font color='#979000'>0</font><font face='Lucida Console'>)</font> <b>{</b><b>}</b>

            dlib::ustring name;
            <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> width;
            rectangle rect;
            widget_group<font color='#5555FF'>*</font> group;
        <b>}</b>;

        <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> selected_tab_;

        array<font color='#5555FF'>&lt;</font>tab_data<font color='#5555FF'>&gt;</font> tabs;

        <font color='#0000FF'>const</font> <font color='#0000FF'><u>long</u></font> left_pad;
        <font color='#0000FF'>const</font> <font color='#0000FF'><u>long</u></font> right_pad;
        <font color='#0000FF'>const</font> <font color='#0000FF'><u>long</u></font> top_pad;
        <font color='#0000FF'>const</font> <font color='#0000FF'><u>long</u></font> bottom_pad;

        any_function<font color='#5555FF'>&lt;</font><font color='#0000FF'><u>void</u></font><font face='Lucida Console'>(</font><font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font>,<font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font><font face='Lucida Console'>)</font><font color='#5555FF'>&gt;</font> event_handler;

        <font color='#009900'>// restricted functions
</font>        <b><a name='tabbed_display'></a>tabbed_display</b><font face='Lucida Console'>(</font>tabbed_display<font color='#5555FF'>&amp;</font><font face='Lucida Console'>)</font>;        <font color='#009900'>// copy constructor
</font>        tabbed_display<font color='#5555FF'>&amp;</font> <b><a name='operator'></a>operator</b><font color='#5555FF'>=</font><font face='Lucida Console'>(</font>tabbed_display<font color='#5555FF'>&amp;</font><font face='Lucida Console'>)</font>;    <font color='#009900'>// assignment operator
</font>    <b>}</b>;

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font><font color='#009900'>// ----------------------------------------------------------------------------------------
</font>    <font color='#009900'>// class named_rectangle
</font><font color='#009900'>// ----------------------------------------------------------------------------------------
</font><font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'>class</font> <b><a name='named_rectangle'></a>named_rectangle</b> : <font color='#0000FF'>public</font> drawable 
    <b>{</b>
        <font color='#009900'>/*!
            INITIAL VALUE
                name == ""

            CONVENTION
                name_ == name()
        !*/</font>

    <font color='#0000FF'>public</font>:

        <b><a name='named_rectangle'></a>named_rectangle</b><font face='Lucida Console'>(</font>  
            drawable_window<font color='#5555FF'>&amp;</font> w
        <font face='Lucida Console'>)</font>;

        <font color='#0000FF'>virtual</font> ~<b><a name='named_rectangle'></a>named_rectangle</b><font face='Lucida Console'>(</font>
        <font face='Lucida Console'>)</font>;

        <font color='#0000FF'><u>void</u></font> <b><a name='set_size'></a>set_size</b> <font face='Lucida Console'>(</font>
            <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> width,
            <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> height
        <font face='Lucida Console'>)</font>;

        <font color='#0000FF'><u>void</u></font> <b><a name='set_name'></a>set_name</b> <font face='Lucida Console'>(</font>
            <font color='#0000FF'>const</font> std::string<font color='#5555FF'>&amp;</font> name
        <font face='Lucida Console'>)</font>;

        <font color='#0000FF'><u>void</u></font> <b><a name='set_name'></a>set_name</b> <font face='Lucida Console'>(</font>
            <font color='#0000FF'>const</font> std::wstring<font color='#5555FF'>&amp;</font> name
        <font face='Lucida Console'>)</font>;

        <font color='#0000FF'><u>void</u></font> <b><a name='set_name'></a>set_name</b> <font face='Lucida Console'>(</font>
            <font color='#0000FF'>const</font> dlib::ustring<font color='#5555FF'>&amp;</font> name
        <font face='Lucida Console'>)</font>;

        <font color='#0000FF'>const</font> std::string <b><a name='name'></a>name</b> <font face='Lucida Console'>(</font>
        <font face='Lucida Console'>)</font> <font color='#0000FF'>const</font>;

        <font color='#0000FF'>const</font> std::wstring <b><a name='wname'></a>wname</b> <font face='Lucida Console'>(</font>
        <font face='Lucida Console'>)</font> <font color='#0000FF'>const</font>;

        <font color='#0000FF'>const</font> dlib::ustring <b><a name='uname'></a>uname</b> <font face='Lucida Console'>(</font>
        <font face='Lucida Console'>)</font> <font color='#0000FF'>const</font>;

        <font color='#0000FF'><u>void</u></font> <b><a name='wrap_around'></a>wrap_around</b> <font face='Lucida Console'>(</font>
            <font color='#0000FF'>const</font> rectangle<font color='#5555FF'>&amp;</font> rect
        <font face='Lucida Console'>)</font>;

        <font color='#0000FF'><u>void</u></font> <b><a name='set_main_font'></a>set_main_font</b> <font face='Lucida Console'>(</font>
            <font color='#0000FF'>const</font> shared_ptr_thread_safe<font color='#5555FF'>&lt;</font>font<font color='#5555FF'>&gt;</font><font color='#5555FF'>&amp;</font> f
        <font face='Lucida Console'>)</font>;

    <font color='#0000FF'>protected</font>:

        <font color='#0000FF'><u>void</u></font> <b><a name='draw'></a>draw</b> <font face='Lucida Console'>(</font>
            <font color='#0000FF'>const</font> canvas<font color='#5555FF'>&amp;</font> c
        <font face='Lucida Console'>)</font> <font color='#0000FF'>const</font>;

    <font color='#0000FF'>private</font>:

        <font color='#0000FF'><u>void</u></font> <b><a name='make_name_fit_in_rect'></a>make_name_fit_in_rect</b> <font face='Lucida Console'>(</font>
        <font face='Lucida Console'>)</font>;

        dlib::ustring name_;
        <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> name_width;
        <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> name_height;

        <font color='#009900'>// restricted functions
</font>        <b><a name='named_rectangle'></a>named_rectangle</b><font face='Lucida Console'>(</font>named_rectangle<font color='#5555FF'>&amp;</font><font face='Lucida Console'>)</font>;        <font color='#009900'>// copy constructor
</font>        named_rectangle<font color='#5555FF'>&amp;</font> <b><a name='operator'></a>operator</b><font color='#5555FF'>=</font><font face='Lucida Console'>(</font>named_rectangle<font color='#5555FF'>&amp;</font><font face='Lucida Console'>)</font>;    <font color='#009900'>// assignment operator
</font>    <b>}</b>;

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font><font color='#009900'>// ----------------------------------------------------------------------------------------
</font>    <font color='#009900'>// class mouse_tracker
</font><font color='#009900'>// ----------------------------------------------------------------------------------------
</font><font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'>class</font> <b><a name='mouse_tracker'></a>mouse_tracker</b> : <font color='#0000FF'>public</font> draggable 
    <b>{</b>

    <font color='#0000FF'>public</font>:

        <b><a name='mouse_tracker'></a>mouse_tracker</b><font face='Lucida Console'>(</font>  
            drawable_window<font color='#5555FF'>&amp;</font> w
        <font face='Lucida Console'>)</font>; 

        ~<b><a name='mouse_tracker'></a>mouse_tracker</b><font face='Lucida Console'>(</font>
        <font face='Lucida Console'>)</font>;

        <font color='#0000FF'><u>void</u></font> <b><a name='show'></a>show</b> <font face='Lucida Console'>(</font>
        <font face='Lucida Console'>)</font>;

        <font color='#0000FF'><u>void</u></font> <b><a name='hide'></a>hide</b> <font face='Lucida Console'>(</font>
        <font face='Lucida Console'>)</font>;

        <font color='#0000FF'><u>void</u></font> <b><a name='enable'></a>enable</b> <font face='Lucida Console'>(</font>
        <font face='Lucida Console'>)</font>;

        <font color='#0000FF'><u>void</u></font> <b><a name='disable'></a>disable</b> <font face='Lucida Console'>(</font>
        <font face='Lucida Console'>)</font>;

        <font color='#0000FF'><u>void</u></font> <b><a name='set_pos'></a>set_pos</b> <font face='Lucida Console'>(</font>
            <font color='#0000FF'><u>long</u></font> x,
            <font color='#0000FF'><u>long</u></font> y
        <font face='Lucida Console'>)</font>;

        <font color='#0000FF'><u>void</u></font> <b><a name='set_main_font'></a>set_main_font</b> <font face='Lucida Console'>(</font>
            <font color='#0000FF'>const</font> shared_ptr_thread_safe<font color='#5555FF'>&lt;</font>font<font color='#5555FF'>&gt;</font><font color='#5555FF'>&amp;</font> f
        <font face='Lucida Console'>)</font>;

    <font color='#0000FF'>protected</font>:

        <font color='#0000FF'><u>void</u></font> <b><a name='on_mouse_move'></a>on_mouse_move</b> <font face='Lucida Console'>(</font>
            <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> state,
            <font color='#0000FF'><u>long</u></font> x,
            <font color='#0000FF'><u>long</u></font> y
        <font face='Lucida Console'>)</font>;

        <font color='#0000FF'><u>void</u></font> <b><a name='on_drag'></a>on_drag</b> <font face='Lucida Console'>(</font>
        <font face='Lucida Console'>)</font>;

        <font color='#0000FF'><u>void</u></font> <b><a name='draw'></a>draw</b> <font face='Lucida Console'>(</font>
            <font color='#0000FF'>const</font> canvas<font color='#5555FF'>&amp;</font> c
        <font face='Lucida Console'>)</font> <font color='#0000FF'>const</font>;

        <font color='#0000FF'><u>void</u></font> <b><a name='on_mouse_down'></a>on_mouse_down</b> <font face='Lucida Console'>(</font>
            <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> btn,
            <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> state,
            <font color='#0000FF'><u>long</u></font> x,
            <font color='#0000FF'><u>long</u></font> y,
            <font color='#0000FF'><u>bool</u></font> is_double_click
        <font face='Lucida Console'>)</font>;


    <font color='#0000FF'>private</font>:

        <font color='#0000FF'>const</font> <font color='#0000FF'><u>long</u></font> offset;
        named_rectangle nr;
        label x_label;
        label y_label; 
        std::ostringstream sout;

        <font color='#0000FF'><u>long</u></font> click_x, click_y;

        <font color='#009900'>// restricted functions
</font>        <b><a name='mouse_tracker'></a>mouse_tracker</b><font face='Lucida Console'>(</font>mouse_tracker<font color='#5555FF'>&amp;</font><font face='Lucida Console'>)</font>;        <font color='#009900'>// copy constructor
</font>        mouse_tracker<font color='#5555FF'>&amp;</font> <b><a name='operator'></a>operator</b><font color='#5555FF'>=</font><font face='Lucida Console'>(</font>mouse_tracker<font color='#5555FF'>&amp;</font><font face='Lucida Console'>)</font>;    <font color='#009900'>// assignment operator
</font>    <b>}</b>;

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font><font color='#009900'>// ----------------------------------------------------------------------------------------
</font>    <font color='#009900'>// function message_box()  
</font><font color='#009900'>// ----------------------------------------------------------------------------------------
</font><font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'>namespace</font> message_box_helper
    <b>{</b>
        <font color='#0000FF'>class</font> <b><a name='box_win'></a>box_win</b> : <font color='#0000FF'>public</font> drawable_window
        <b>{</b>
            <font color='#0000FF'><u>void</u></font> <b><a name='initialize'></a>initialize</b> <font face='Lucida Console'>(</font>
            <font face='Lucida Console'>)</font>;
        <font color='#0000FF'>public</font>:
            <b><a name='box_win'></a>box_win</b> <font face='Lucida Console'>(</font>
                <font color='#0000FF'>const</font> std::string<font color='#5555FF'>&amp;</font> title_,
                <font color='#0000FF'>const</font> std::string<font color='#5555FF'>&amp;</font> message_
            <font face='Lucida Console'>)</font>;

            <b><a name='box_win'></a>box_win</b> <font face='Lucida Console'>(</font>
                <font color='#0000FF'>const</font> std::wstring<font color='#5555FF'>&amp;</font> title_,
                <font color='#0000FF'>const</font> std::wstring<font color='#5555FF'>&amp;</font> message_
            <font face='Lucida Console'>)</font>;

            <b><a name='box_win'></a>box_win</b> <font face='Lucida Console'>(</font>
                <font color='#0000FF'>const</font> dlib::ustring<font color='#5555FF'>&amp;</font> title_,
                <font color='#0000FF'>const</font> dlib::ustring<font color='#5555FF'>&amp;</font> message_
            <font face='Lucida Console'>)</font>;

            ~<b><a name='box_win'></a>box_win</b> <font face='Lucida Console'>(</font>
            <font face='Lucida Console'>)</font>;

            <font color='#0000FF'><u>void</u></font> <b><a name='set_click_handler'></a>set_click_handler</b> <font face='Lucida Console'>(</font>
                <font color='#0000FF'>const</font> any_function<font color='#5555FF'>&lt;</font><font color='#0000FF'><u>void</u></font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>&gt;</font><font color='#5555FF'>&amp;</font> event_handler_
            <font face='Lucida Console'>)</font>
            <b>{</b>
                auto_mutex <font color='#BB00BB'>M</font><font face='Lucida Console'>(</font>wm<font face='Lucida Console'>)</font>;
                event_handler <font color='#5555FF'>=</font> event_handler_;
            <b>}</b>

        <font color='#0000FF'>private</font>:

            <font color='#0000FF'>static</font> <font color='#0000FF'><u>void</u></font> <b><a name='deleter_thread'></a>deleter_thread</b> <font face='Lucida Console'>(</font>
                <font color='#0000FF'><u>void</u></font><font color='#5555FF'>*</font> param
            <font face='Lucida Console'>)</font>;

            <font color='#0000FF'><u>void</u></font> <b><a name='on_click'></a>on_click</b> <font face='Lucida Console'>(</font>
            <font face='Lucida Console'>)</font>;

            on_close_return_code <b><a name='on_window_close'></a>on_window_close</b> <font face='Lucida Console'>(</font>
            <font face='Lucida Console'>)</font>;

            <font color='#0000FF'>const</font> std::wstring title;
            <font color='#0000FF'>const</font> std::wstring message;
            label msg;
            button btn_ok;

            any_function<font color='#5555FF'>&lt;</font><font color='#0000FF'><u>void</u></font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>&gt;</font> event_handler;
        <b>}</b>;

        <font color='#0000FF'>class</font> <b><a name='blocking_box_win'></a>blocking_box_win</b> : <font color='#0000FF'>public</font> drawable_window
        <b>{</b>
            <font color='#0000FF'><u>void</u></font> <b><a name='initialize'></a>initialize</b> <font face='Lucida Console'>(</font>
            <font face='Lucida Console'>)</font>;

        <font color='#0000FF'>public</font>:
            <b><a name='blocking_box_win'></a>blocking_box_win</b> <font face='Lucida Console'>(</font>
                <font color='#0000FF'>const</font> std::string<font color='#5555FF'>&amp;</font> title_,
                <font color='#0000FF'>const</font> std::string<font color='#5555FF'>&amp;</font> message_
            <font face='Lucida Console'>)</font>;

            <b><a name='blocking_box_win'></a>blocking_box_win</b> <font face='Lucida Console'>(</font>
                <font color='#0000FF'>const</font> std::wstring<font color='#5555FF'>&amp;</font> title_,
                <font color='#0000FF'>const</font> std::wstring<font color='#5555FF'>&amp;</font> message_
            <font face='Lucida Console'>)</font>;

            <b><a name='blocking_box_win'></a>blocking_box_win</b> <font face='Lucida Console'>(</font>
                <font color='#0000FF'>const</font> dlib::ustring<font color='#5555FF'>&amp;</font> title_,
                <font color='#0000FF'>const</font> dlib::ustring<font color='#5555FF'>&amp;</font> message_
            <font face='Lucida Console'>)</font>;

            ~<b><a name='blocking_box_win'></a>blocking_box_win</b> <font face='Lucida Console'>(</font>
            <font face='Lucida Console'>)</font>;

        <font color='#0000FF'>private</font>:

            <font color='#0000FF'><u>void</u></font> <b><a name='on_click'></a>on_click</b> <font face='Lucida Console'>(</font>
            <font face='Lucida Console'>)</font>;

            <font color='#0000FF'>const</font> std::wstring title;
            <font color='#0000FF'>const</font> std::wstring message;
            label msg;
            button btn_ok;
        <b>}</b>;
    <b>}</b>

    <font color='#0000FF'>template</font> <font color='#5555FF'>&lt;</font>
        <font color='#0000FF'>typename</font> T
        <font color='#5555FF'>&gt;</font>
    <font color='#0000FF'><u>void</u></font> <b><a name='message_box'></a>message_box</b> <font face='Lucida Console'>(</font>
        <font color='#0000FF'>const</font> std::string<font color='#5555FF'>&amp;</font> title,
        <font color='#0000FF'>const</font> std::string<font color='#5555FF'>&amp;</font> message,
        T<font color='#5555FF'>&amp;</font> object,
        <font color='#0000FF'><u>void</u></font> <font face='Lucida Console'>(</font>T::<font color='#5555FF'>*</font>event_handler<font face='Lucida Console'>)</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> 
    <font face='Lucida Console'>)</font>
    <b>{</b>
        <font color='#0000FF'>using</font> <font color='#0000FF'>namespace</font> message_box_helper;
        box_win<font color='#5555FF'>*</font> win <font color='#5555FF'>=</font> <font color='#0000FF'>new</font> <font color='#BB00BB'>box_win</font><font face='Lucida Console'>(</font>title,message<font face='Lucida Console'>)</font>;
        win<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font><font color='#BB00BB'>set_click_handler</font><font face='Lucida Console'>(</font><font color='#BB00BB'>make_mfp</font><font face='Lucida Console'>(</font>object,event_handler<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
    <b>}</b>

    <font color='#0000FF'>inline</font> <font color='#0000FF'><u>void</u></font> <b><a name='message_box'></a>message_box</b> <font face='Lucida Console'>(</font>
        <font color='#0000FF'>const</font> std::string<font color='#5555FF'>&amp;</font> title,
        <font color='#0000FF'>const</font> std::string<font color='#5555FF'>&amp;</font> message,
        <font color='#0000FF'>const</font> any_function<font color='#5555FF'>&lt;</font><font color='#0000FF'><u>void</u></font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>&gt;</font><font color='#5555FF'>&amp;</font> event_handler
    <font face='Lucida Console'>)</font>
    <b>{</b>
        <font color='#0000FF'>using</font> <font color='#0000FF'>namespace</font> message_box_helper;
        box_win<font color='#5555FF'>*</font> win <font color='#5555FF'>=</font> <font color='#0000FF'>new</font> <font color='#BB00BB'>box_win</font><font face='Lucida Console'>(</font>title,message<font face='Lucida Console'>)</font>;
        win<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font><font color='#BB00BB'>set_click_handler</font><font face='Lucida Console'>(</font>event_handler<font face='Lucida Console'>)</font>;
    <b>}</b>

    <font color='#0000FF'>inline</font> <font color='#0000FF'><u>void</u></font> <b><a name='message_box'></a>message_box</b> <font face='Lucida Console'>(</font>
        <font color='#0000FF'>const</font> std::string<font color='#5555FF'>&amp;</font> title,
        <font color='#0000FF'>const</font> std::string<font color='#5555FF'>&amp;</font> message
    <font face='Lucida Console'>)</font>
    <b>{</b>
        <font color='#0000FF'>using</font> <font color='#0000FF'>namespace</font> message_box_helper;
        <font color='#0000FF'>new</font> <font color='#BB00BB'>box_win</font><font face='Lucida Console'>(</font>title,message<font face='Lucida Console'>)</font>;
    <b>}</b>

    <font color='#0000FF'>inline</font> <font color='#0000FF'><u>void</u></font> <b><a name='message_box_blocking'></a>message_box_blocking</b> <font face='Lucida Console'>(</font>
        <font color='#0000FF'>const</font> std::string<font color='#5555FF'>&amp;</font> title,
        <font color='#0000FF'>const</font> std::string<font color='#5555FF'>&amp;</font> message
    <font face='Lucida Console'>)</font>
    <b>{</b>
        <font color='#0000FF'>using</font> <font color='#0000FF'>namespace</font> message_box_helper;
        blocking_box_win <font color='#BB00BB'>w</font><font face='Lucida Console'>(</font>title,message<font face='Lucida Console'>)</font>;
        w.<font color='#BB00BB'>wait_until_closed</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font><font color='#009900'>// ----------------------------------------------------------------------------------------
</font>    <font color='#009900'>// class list_box
</font><font color='#009900'>// ----------------------------------------------------------------------------------------
</font><font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'>namespace</font> list_box_helper<b>{</b>
    <font color='#0000FF'>template</font> <font color='#5555FF'>&lt;</font><font color='#0000FF'>typename</font> S <font color='#5555FF'>=</font> std::string<font color='#5555FF'>&gt;</font>
    <font color='#0000FF'>class</font> <b><a name='list_box'></a>list_box</b> : <font color='#0000FF'>public</font> scrollable_region, 
                     <font color='#0000FF'>public</font> enumerable<font color='#5555FF'>&lt;</font><font color='#0000FF'>const</font> S<font color='#5555FF'>&gt;</font>
    <b>{</b>
        <font color='#009900'>/*!
            INITIAL VALUE
                - ms_enabled == false
                - items.size() == 0
                - last_selected = 0

            CONVENTION
                - size() == items.size()
                - (*this)[i] == items[i].name
                - is_selected(i) == items[i].is_selected
                - ms_enabled == multiple_select_enabled()

                - items[i].width == the width of items[i].name as given by font::compute_size() 
                - items[i].height == the height of items[i].name as given by font::compute_size() 

                - last_selected == the last item the user selected
        !*/</font>

    <font color='#0000FF'>public</font>:

        <b><a name='list_box'></a>list_box</b><font face='Lucida Console'>(</font>  
            drawable_window<font color='#5555FF'>&amp;</font> w
        <font face='Lucida Console'>)</font>;

        ~<b><a name='list_box'></a>list_box</b><font face='Lucida Console'>(</font>
        <font face='Lucida Console'>)</font>;

        <font color='#0000FF'><u>bool</u></font> <b><a name='is_selected'></a>is_selected</b> <font face='Lucida Console'>(</font>
            <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> index
        <font face='Lucida Console'>)</font> <font color='#0000FF'>const</font>;

        <font color='#0000FF'><u>void</u></font> <b><a name='select'></a>select</b> <font face='Lucida Console'>(</font>
            <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> index 
        <font face='Lucida Console'>)</font>;

        <font color='#0000FF'><u>void</u></font> <b><a name='unselect'></a>unselect</b> <font face='Lucida Console'>(</font>
            <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> index 
        <font face='Lucida Console'>)</font>;

        <font color='#0000FF'>template</font> <font color='#5555FF'>&lt;</font>
            <font color='#0000FF'>typename</font> style_type
            <font color='#5555FF'>&gt;</font>
        <font color='#0000FF'><u>void</u></font> <b><a name='set_style'></a>set_style</b> <font face='Lucida Console'>(</font>
            <font color='#0000FF'>const</font> style_type<font color='#5555FF'>&amp;</font> style_
        <font face='Lucida Console'>)</font>
        <b>{</b>
            auto_mutex <font color='#BB00BB'>M</font><font face='Lucida Console'>(</font>m<font face='Lucida Console'>)</font>;
            style.<font color='#BB00BB'>reset</font><font face='Lucida Console'>(</font><font color='#0000FF'>new</font> <font color='#BB00BB'>style_type</font><font face='Lucida Console'>(</font>style_<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
            scrollable_region::<font color='#BB00BB'>set_style</font><font face='Lucida Console'>(</font>style_.<font color='#BB00BB'>get_scrollable_region_style</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
            parent.<font color='#BB00BB'>invalidate_rectangle</font><font face='Lucida Console'>(</font>rect<font face='Lucida Console'>)</font>;
        <b>}</b>

        <font color='#0000FF'>template</font> <font color='#5555FF'>&lt;</font><font color='#0000FF'>typename</font> T<font color='#5555FF'>&gt;</font>
        <font color='#0000FF'><u>void</u></font> <b><a name='get_selected'></a>get_selected</b> <font face='Lucida Console'>(</font>
            T<font color='#5555FF'>&amp;</font> list
        <font face='Lucida Console'>)</font> <font color='#0000FF'>const</font>
        <b>{</b>
            auto_mutex <font color='#BB00BB'>M</font><font face='Lucida Console'>(</font>m<font face='Lucida Console'>)</font>;
            list.<font color='#BB00BB'>clear</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
            <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font><font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> i <font color='#5555FF'>=</font> <font color='#979000'>0</font>; i <font color='#5555FF'>&lt;</font> items.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>i<font face='Lucida Console'>)</font>
            <b>{</b>
                <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>items[i].is_selected<font face='Lucida Console'>)</font>
                <b>{</b>
                    <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> idx <font color='#5555FF'>=</font> i;
                    list.<font color='#BB00BB'>enqueue</font><font face='Lucida Console'>(</font>idx<font face='Lucida Console'>)</font>;
                <b>}</b>
            <b>}</b>
        <b>}</b>

        <font color='#0000FF'>template</font> <font color='#5555FF'>&lt;</font><font color='#0000FF'>typename</font> T<font color='#5555FF'>&gt;</font>
        <font color='#0000FF'><u>void</u></font> <b><a name='load'></a>load</b> <font face='Lucida Console'>(</font>
            <font color='#0000FF'>const</font> T<font color='#5555FF'>&amp;</font> list
        <font face='Lucida Console'>)</font>
        <b>{</b>
            auto_mutex <font color='#BB00BB'>M</font><font face='Lucida Console'>(</font>m<font face='Lucida Console'>)</font>;
            items.<font color='#BB00BB'>clear</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
            <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> i <font color='#5555FF'>=</font> <font color='#979000'>0</font>;
            items.<font color='#BB00BB'>set_max_size</font><font face='Lucida Console'>(</font>list.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
            items.<font color='#BB00BB'>set_size</font><font face='Lucida Console'>(</font>list.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
            list.<font color='#BB00BB'>reset</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
            <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> max_width <font color='#5555FF'>=</font> <font color='#979000'>0</font>;
            <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> total_height <font color='#5555FF'>=</font> <font color='#979000'>0</font>;
            <font color='#0000FF'>while</font> <font face='Lucida Console'>(</font>list.<font color='#BB00BB'>move_next</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>
            <b>{</b>
                items[i].is_selected <font color='#5555FF'>=</font> <font color='#979000'>false</font>;
                items[i].name <font color='#5555FF'>=</font> list.<font color='#BB00BB'>element</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
                mfont<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font><font color='#BB00BB'>compute_size</font><font face='Lucida Console'>(</font>items[i].name,items[i].width, items[i].height<font face='Lucida Console'>)</font>;

                <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>items[i].width <font color='#5555FF'>&gt;</font> max_width<font face='Lucida Console'>)</font>
                    max_width <font color='#5555FF'>=</font> items[i].width;
                total_height <font color='#5555FF'>+</font><font color='#5555FF'>=</font> items[i].height;

                <font color='#5555FF'>+</font><font color='#5555FF'>+</font>i;
            <b>}</b>
            <font color='#BB00BB'>set_total_rect_size</font><font face='Lucida Console'>(</font>max_width, total_height<font face='Lucida Console'>)</font>;

            parent.<font color='#BB00BB'>invalidate_rectangle</font><font face='Lucida Console'>(</font>rect<font face='Lucida Console'>)</font>;
            last_selected <font color='#5555FF'>=</font> <font color='#979000'>0</font>;
        <b>}</b>

        <font color='#0000FF'>const</font> S<font color='#5555FF'>&amp;</font> <b><a name='operator'></a>operator</b>[] <font face='Lucida Console'>(</font>
            <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> index
        <font face='Lucida Console'>)</font> <font color='#0000FF'>const</font>;

        <font color='#0000FF'><u>bool</u></font> <b><a name='multiple_select_enabled'></a>multiple_select_enabled</b> <font face='Lucida Console'>(</font>
        <font face='Lucida Console'>)</font> <font color='#0000FF'>const</font>;

        <font color='#0000FF'><u>void</u></font> <b><a name='enable_multiple_select'></a>enable_multiple_select</b> <font face='Lucida Console'>(</font>
        <font face='Lucida Console'>)</font>; 

        <font color='#0000FF'><u>void</u></font> <b><a name='disable_multiple_select'></a>disable_multiple_select</b> <font face='Lucida Console'>(</font>
        <font face='Lucida Console'>)</font>;

        <font color='#0000FF'>template</font> <font color='#5555FF'>&lt;</font>
            <font color='#0000FF'>typename</font> T
            <font color='#5555FF'>&gt;</font>
        <font color='#0000FF'><u>void</u></font> <b><a name='set_double_click_handler'></a>set_double_click_handler</b> <font face='Lucida Console'>(</font>
            T<font color='#5555FF'>&amp;</font> object,
            <font color='#0000FF'><u>void</u></font> <font face='Lucida Console'>(</font>T::<font color='#5555FF'>*</font>eh<font face='Lucida Console'>)</font><font face='Lucida Console'>(</font><font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> index<font face='Lucida Console'>)</font>
        <font face='Lucida Console'>)</font> <b>{</b> auto_mutex <font color='#BB00BB'>M</font><font face='Lucida Console'>(</font>m<font face='Lucida Console'>)</font>; event_handler <font color='#5555FF'>=</font> <font color='#BB00BB'>make_mfp</font><font face='Lucida Console'>(</font>object,eh<font face='Lucida Console'>)</font>; <b>}</b>

        <font color='#0000FF'><u>void</u></font> <b><a name='set_double_click_handler'></a>set_double_click_handler</b> <font face='Lucida Console'>(</font>
            <font color='#0000FF'>const</font> any_function<font color='#5555FF'>&lt;</font><font color='#0000FF'><u>void</u></font><font face='Lucida Console'>(</font><font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font><font face='Lucida Console'>)</font><font color='#5555FF'>&gt;</font><font color='#5555FF'>&amp;</font> eh
        <font face='Lucida Console'>)</font> <b>{</b> auto_mutex <font color='#BB00BB'>M</font><font face='Lucida Console'>(</font>m<font face='Lucida Console'>)</font>; event_handler <font color='#5555FF'>=</font> eh; <b>}</b>

        <font color='#0000FF'>template</font> <font color='#5555FF'>&lt;</font>
            <font color='#0000FF'>typename</font> T
            <font color='#5555FF'>&gt;</font>
        <font color='#0000FF'><u>void</u></font> <b><a name='set_click_handler'></a>set_click_handler</b> <font face='Lucida Console'>(</font>
            T<font color='#5555FF'>&amp;</font> object,
            <font color='#0000FF'><u>void</u></font> <font face='Lucida Console'>(</font>T::<font color='#5555FF'>*</font>eh<font face='Lucida Console'>)</font><font face='Lucida Console'>(</font><font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> index<font face='Lucida Console'>)</font>
        <font face='Lucida Console'>)</font> <b>{</b> auto_mutex <font color='#BB00BB'>M</font><font face='Lucida Console'>(</font>m<font face='Lucida Console'>)</font>; single_click_event_handler <font color='#5555FF'>=</font> <font color='#BB00BB'>make_mfp</font><font face='Lucida Console'>(</font>object,eh<font face='Lucida Console'>)</font>; <b>}</b>

        <font color='#0000FF'><u>void</u></font> <b><a name='set_click_handler'></a>set_click_handler</b> <font face='Lucida Console'>(</font>
            <font color='#0000FF'>const</font> any_function<font color='#5555FF'>&lt;</font><font color='#0000FF'><u>void</u></font><font face='Lucida Console'>(</font><font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font><font face='Lucida Console'>)</font><font color='#5555FF'>&gt;</font><font color='#5555FF'>&amp;</font> eh
        <font face='Lucida Console'>)</font> <b>{</b> auto_mutex <font color='#BB00BB'>M</font><font face='Lucida Console'>(</font>m<font face='Lucida Console'>)</font>; single_click_event_handler <font color='#5555FF'>=</font> eh; <b>}</b>

        <font color='#0000FF'><u>bool</u></font> <b><a name='at_start'></a>at_start</b> <font face='Lucida Console'>(</font>
        <font face='Lucida Console'>)</font> <font color='#0000FF'>const</font>;

        <font color='#0000FF'><u>void</u></font> <b><a name='reset'></a>reset</b> <font face='Lucida Console'>(</font>
        <font face='Lucida Console'>)</font> <font color='#0000FF'>const</font>;

        <font color='#0000FF'><u>bool</u></font> <b><a name='current_element_valid'></a>current_element_valid</b> <font face='Lucida Console'>(</font>
        <font face='Lucida Console'>)</font> <font color='#0000FF'>const</font>;

        <font color='#0000FF'>const</font> S<font color='#5555FF'>&amp;</font> <b><a name='element'></a>element</b> <font face='Lucida Console'>(</font>
        <font face='Lucida Console'>)</font> <font color='#0000FF'>const</font>;

        <font color='#0000FF'>const</font> S<font color='#5555FF'>&amp;</font> <b><a name='element'></a>element</b> <font face='Lucida Console'>(</font>
        <font face='Lucida Console'>)</font>;

        <font color='#0000FF'><u>bool</u></font> <b><a name='move_next'></a>move_next</b> <font face='Lucida Console'>(</font>
        <font face='Lucida Console'>)</font> <font color='#0000FF'>const</font>;

        <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> <b><a name='size'></a>size</b> <font face='Lucida Console'>(</font>
        <font face='Lucida Console'>)</font> <font color='#0000FF'>const</font>;

        <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> <b><a name='get_selected'></a>get_selected</b> <font face='Lucida Console'>(</font>
        <font face='Lucida Console'>)</font> <font color='#0000FF'>const</font>;

        <font color='#0000FF'><u>void</u></font> <b><a name='set_main_font'></a>set_main_font</b> <font face='Lucida Console'>(</font>
            <font color='#0000FF'>const</font> shared_ptr_thread_safe<font color='#5555FF'>&lt;</font>font<font color='#5555FF'>&gt;</font><font color='#5555FF'>&amp;</font> f
        <font face='Lucida Console'>)</font>;

    <font color='#0000FF'>private</font>:

        <font color='#0000FF'><u>void</u></font> <b><a name='on_mouse_down'></a>on_mouse_down</b> <font face='Lucida Console'>(</font>
            <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> btn,
            <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> state,
            <font color='#0000FF'><u>long</u></font> x,
            <font color='#0000FF'><u>long</u></font> y,
            <font color='#0000FF'><u>bool</u></font> is_double_click
        <font face='Lucida Console'>)</font>;

        <font color='#0000FF'><u>void</u></font> <b><a name='draw'></a>draw</b> <font face='Lucida Console'>(</font>
            <font color='#0000FF'>const</font> canvas<font color='#5555FF'>&amp;</font> c
        <font face='Lucida Console'>)</font> <font color='#0000FF'>const</font>;

        <font color='#0000FF'>template</font> <font color='#5555FF'>&lt;</font><font color='#0000FF'>typename</font> SS<font color='#5555FF'>&gt;</font>
        <font color='#0000FF'>struct</font> <b><a name='data'></a>data</b>
        <b>{</b>
            SS name;
            <font color='#0000FF'><u>bool</u></font> is_selected;
            <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> width;
            <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> height;
        <b>}</b>;

        <font color='#0000FF'><u>bool</u></font> ms_enabled;
        array<font color='#5555FF'>&lt;</font>data<font color='#5555FF'>&lt;</font>S<font color='#5555FF'>&gt;</font> <font color='#5555FF'>&gt;</font> items;
        any_function<font color='#5555FF'>&lt;</font><font color='#0000FF'><u>void</u></font><font face='Lucida Console'>(</font><font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font><font face='Lucida Console'>)</font><font color='#5555FF'>&gt;</font> event_handler;
        any_function<font color='#5555FF'>&lt;</font><font color='#0000FF'><u>void</u></font><font face='Lucida Console'>(</font><font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font><font face='Lucida Console'>)</font><font color='#5555FF'>&gt;</font> single_click_event_handler;
        <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> last_selected;

        scoped_ptr<font color='#5555FF'>&lt;</font>list_box_style<font color='#5555FF'>&gt;</font> style;

        <font color='#009900'>// restricted functions
</font>        <b><a name='list_box'></a>list_box</b><font face='Lucida Console'>(</font>list_box<font color='#5555FF'>&amp;</font><font face='Lucida Console'>)</font>;        <font color='#009900'>// copy constructor
</font>        list_box<font color='#5555FF'>&amp;</font> <b><a name='operator'></a>operator</b><font color='#5555FF'>=</font><font face='Lucida Console'>(</font>list_box<font color='#5555FF'>&amp;</font><font face='Lucida Console'>)</font>;    <font color='#009900'>// assignment operator
</font>    <b>}</b>;
    <b>}</b>
    <font color='#0000FF'>typedef</font> list_box_helper::list_box<font color='#5555FF'>&lt;</font>std::string<font color='#5555FF'>&gt;</font> list_box;
    <font color='#0000FF'>typedef</font> list_box_helper::list_box<font color='#5555FF'>&lt;</font>std::wstring<font color='#5555FF'>&gt;</font> wlist_box;
    <font color='#0000FF'>typedef</font> list_box_helper::list_box<font color='#5555FF'>&lt;</font>dlib::ustring<font color='#5555FF'>&gt;</font> ulist_box;

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font><font color='#009900'>// ----------------------------------------------------------------------------------------
</font>    <font color='#009900'>// function open_file_box() 
</font><font color='#009900'>// ----------------------------------------------------------------------------------------
</font><font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'>namespace</font> open_file_box_helper
    <b>{</b>
        <font color='#0000FF'>class</font> <b><a name='box_win'></a>box_win</b> : <font color='#0000FF'>public</font> drawable_window
        <b>{</b>
        <font color='#0000FF'>public</font>:
            <b><a name='box_win'></a>box_win</b> <font face='Lucida Console'>(</font>
                <font color='#0000FF'>const</font> std::string<font color='#5555FF'>&amp;</font> title,
                <font color='#0000FF'><u>bool</u></font> has_text_field <font color='#5555FF'>=</font> <font color='#979000'>false</font>
            <font face='Lucida Console'>)</font>;

            ~<b><a name='box_win'></a>box_win</b> <font face='Lucida Console'>(</font>
            <font face='Lucida Console'>)</font>;

            <font color='#0000FF'><u>void</u></font> <b><a name='set_click_handler'></a>set_click_handler</b> <font face='Lucida Console'>(</font>
                <font color='#0000FF'>const</font> any_function<font color='#5555FF'>&lt;</font><font color='#0000FF'><u>void</u></font><font face='Lucida Console'>(</font><font color='#0000FF'>const</font> std::string<font color='#5555FF'>&amp;</font><font face='Lucida Console'>)</font><font color='#5555FF'>&gt;</font><font color='#5555FF'>&amp;</font> event_handler_
            <font face='Lucida Console'>)</font>
            <b>{</b>
                auto_mutex <font color='#BB00BB'>M</font><font face='Lucida Console'>(</font>wm<font face='Lucida Console'>)</font>;
                event_handler <font color='#5555FF'>=</font> event_handler_;
            <b>}</b>

        <font color='#0000FF'>private</font>:

            <font color='#0000FF'><u>void</u></font> <b><a name='set_sizes'></a>set_sizes</b><font face='Lucida Console'>(</font>
            <font face='Lucida Console'>)</font>;

            <font color='#0000FF'><u>void</u></font> <b><a name='on_window_resized'></a>on_window_resized</b> <font face='Lucida Console'>(</font>
            <font face='Lucida Console'>)</font>;

            <font color='#0000FF'><u>void</u></font> <b><a name='deleter_thread'></a>deleter_thread</b> <font face='Lucida Console'>(</font>
            <font face='Lucida Console'>)</font>;

            <font color='#0000FF'><u>void</u></font> <b><a name='enter_folder'></a>enter_folder</b> <font face='Lucida Console'>(</font>
                <font color='#0000FF'>const</font> std::string<font color='#5555FF'>&amp;</font> folder_name
            <font face='Lucida Console'>)</font>;

            <font color='#0000FF'><u>void</u></font> <b><a name='on_dirs_click'></a>on_dirs_click</b> <font face='Lucida Console'>(</font>
                <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> idx
            <font face='Lucida Console'>)</font>;

            <font color='#0000FF'><u>void</u></font> <b><a name='on_files_click'></a>on_files_click</b> <font face='Lucida Console'>(</font>
                <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> idx
            <font face='Lucida Console'>)</font>;

            <font color='#0000FF'><u>void</u></font> <b><a name='on_files_double_click'></a>on_files_double_click</b> <font face='Lucida Console'>(</font>
                <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> 
            <font face='Lucida Console'>)</font>;

            <font color='#0000FF'><u>void</u></font> <b><a name='on_cancel_click'></a>on_cancel_click</b> <font face='Lucida Console'>(</font>
            <font face='Lucida Console'>)</font>;

            <font color='#0000FF'><u>void</u></font> <b><a name='on_open_click'></a>on_open_click</b> <font face='Lucida Console'>(</font>
            <font face='Lucida Console'>)</font>;

            <font color='#0000FF'><u>void</u></font> <b><a name='on_path_button_click'></a>on_path_button_click</b> <font face='Lucida Console'>(</font>
                toggle_button<font color='#5555FF'>&amp;</font> btn
            <font face='Lucida Console'>)</font>;

            <font color='#0000FF'><u>bool</u></font> <b><a name='set_dir'></a>set_dir</b> <font face='Lucida Console'>(</font>
                <font color='#0000FF'>const</font> std::string<font color='#5555FF'>&amp;</font> dir
            <font face='Lucida Console'>)</font>;

            <font color='#0000FF'><u>void</u></font> <b><a name='on_root_click'></a>on_root_click</b> <font face='Lucida Console'>(</font>
            <font face='Lucida Console'>)</font>;

            on_close_return_code <b><a name='on_window_close'></a>on_window_close</b> <font face='Lucida Console'>(</font>
            <font face='Lucida Console'>)</font>;

            label lbl_dirs;
            label lbl_files;
            label lbl_file_name;
            list_box lb_dirs;
            list_box lb_files;
            button btn_ok;
            button btn_cancel;
            toggle_button btn_root;
            text_field tf_file_name;
            std::string path;
            std::string prefix;
            <font color='#0000FF'><u>int</u></font> cur_dir;

            any_function<font color='#5555FF'>&lt;</font><font color='#0000FF'><u>void</u></font><font face='Lucida Console'>(</font><font color='#0000FF'>const</font> std::string<font color='#5555FF'>&amp;</font><font face='Lucida Console'>)</font><font color='#5555FF'>&gt;</font> event_handler;
            sequence<font color='#5555FF'>&lt;</font>scoped_ptr<font color='#5555FF'>&lt;</font>toggle_button<font color='#5555FF'>&gt;</font> <font color='#5555FF'>&gt;</font>::kernel_2a_c sob;
        <b>}</b>;
    <b>}</b>

    <font color='#0000FF'>template</font> <font color='#5555FF'>&lt;</font>
        <font color='#0000FF'>typename</font> T
        <font color='#5555FF'>&gt;</font>
    <font color='#0000FF'><u>void</u></font> <b><a name='open_file_box'></a>open_file_box</b> <font face='Lucida Console'>(</font>
        T<font color='#5555FF'>&amp;</font> object,
        <font color='#0000FF'><u>void</u></font> <font face='Lucida Console'>(</font>T::<font color='#5555FF'>*</font>event_handler<font face='Lucida Console'>)</font><font face='Lucida Console'>(</font><font color='#0000FF'>const</font> std::string<font color='#5555FF'>&amp;</font><font face='Lucida Console'>)</font> 
    <font face='Lucida Console'>)</font>
    <b>{</b>
        <font color='#0000FF'>using</font> <font color='#0000FF'>namespace</font> open_file_box_helper;
        box_win<font color='#5555FF'>*</font> win <font color='#5555FF'>=</font> <font color='#0000FF'>new</font> <font color='#BB00BB'>box_win</font><font face='Lucida Console'>(</font>"<font color='#CC0000'>Open File</font>",<font color='#979000'>true</font><font face='Lucida Console'>)</font>;
        win<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font><font color='#BB00BB'>set_click_handler</font><font face='Lucida Console'>(</font><font color='#BB00BB'>make_mfp</font><font face='Lucida Console'>(</font>object,event_handler<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
    <b>}</b>

    <font color='#0000FF'>inline</font> <font color='#0000FF'><u>void</u></font> <b><a name='open_file_box'></a>open_file_box</b> <font face='Lucida Console'>(</font>
        <font color='#0000FF'>const</font> any_function<font color='#5555FF'>&lt;</font><font color='#0000FF'><u>void</u></font><font face='Lucida Console'>(</font><font color='#0000FF'>const</font> std::string<font color='#5555FF'>&amp;</font><font face='Lucida Console'>)</font><font color='#5555FF'>&gt;</font><font color='#5555FF'>&amp;</font> event_handler
    <font face='Lucida Console'>)</font>
    <b>{</b>
        <font color='#0000FF'>using</font> <font color='#0000FF'>namespace</font> open_file_box_helper;
        box_win<font color='#5555FF'>*</font> win <font color='#5555FF'>=</font> <font color='#0000FF'>new</font> <font color='#BB00BB'>box_win</font><font face='Lucida Console'>(</font>"<font color='#CC0000'>Open File</font>",<font color='#979000'>true</font><font face='Lucida Console'>)</font>;
        win<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font><font color='#BB00BB'>set_click_handler</font><font face='Lucida Console'>(</font>event_handler<font face='Lucida Console'>)</font>;
    <b>}</b>

    <font color='#0000FF'>template</font> <font color='#5555FF'>&lt;</font>
        <font color='#0000FF'>typename</font> T
        <font color='#5555FF'>&gt;</font>
    <font color='#0000FF'><u>void</u></font> <b><a name='open_existing_file_box'></a>open_existing_file_box</b> <font face='Lucida Console'>(</font>
        T<font color='#5555FF'>&amp;</font> object,
        <font color='#0000FF'><u>void</u></font> <font face='Lucida Console'>(</font>T::<font color='#5555FF'>*</font>event_handler<font face='Lucida Console'>)</font><font face='Lucida Console'>(</font><font color='#0000FF'>const</font> std::string<font color='#5555FF'>&amp;</font><font face='Lucida Console'>)</font> 
    <font face='Lucida Console'>)</font>
    <b>{</b>
        <font color='#0000FF'>using</font> <font color='#0000FF'>namespace</font> open_file_box_helper;
        box_win<font color='#5555FF'>*</font> win <font color='#5555FF'>=</font> <font color='#0000FF'>new</font> <font color='#BB00BB'>box_win</font><font face='Lucida Console'>(</font>"<font color='#CC0000'>Open File</font>"<font face='Lucida Console'>)</font>;
        win<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font><font color='#BB00BB'>set_click_handler</font><font face='Lucida Console'>(</font><font color='#BB00BB'>make_mfp</font><font face='Lucida Console'>(</font>object,event_handler<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
    <b>}</b>

    <font color='#0000FF'>inline</font> <font color='#0000FF'><u>void</u></font> <b><a name='open_existing_file_box'></a>open_existing_file_box</b> <font face='Lucida Console'>(</font>
        <font color='#0000FF'>const</font> any_function<font color='#5555FF'>&lt;</font><font color='#0000FF'><u>void</u></font><font face='Lucida Console'>(</font><font color='#0000FF'>const</font> std::string<font color='#5555FF'>&amp;</font><font face='Lucida Console'>)</font><font color='#5555FF'>&gt;</font><font color='#5555FF'>&amp;</font> event_handler
    <font face='Lucida Console'>)</font>
    <b>{</b>
        <font color='#0000FF'>using</font> <font color='#0000FF'>namespace</font> open_file_box_helper;
        box_win<font color='#5555FF'>*</font> win <font color='#5555FF'>=</font> <font color='#0000FF'>new</font> <font color='#BB00BB'>box_win</font><font face='Lucida Console'>(</font>"<font color='#CC0000'>Open File</font>"<font face='Lucida Console'>)</font>;
        win<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font><font color='#BB00BB'>set_click_handler</font><font face='Lucida Console'>(</font>event_handler<font face='Lucida Console'>)</font>;
    <b>}</b>

    <font color='#0000FF'>template</font> <font color='#5555FF'>&lt;</font>
        <font color='#0000FF'>typename</font> T
        <font color='#5555FF'>&gt;</font>
    <font color='#0000FF'><u>void</u></font> <b><a name='save_file_box'></a>save_file_box</b> <font face='Lucida Console'>(</font>
        T<font color='#5555FF'>&amp;</font> object,
        <font color='#0000FF'><u>void</u></font> <font face='Lucida Console'>(</font>T::<font color='#5555FF'>*</font>event_handler<font face='Lucida Console'>)</font><font face='Lucida Console'>(</font><font color='#0000FF'>const</font> std::string<font color='#5555FF'>&amp;</font><font face='Lucida Console'>)</font> 
    <font face='Lucida Console'>)</font>
    <b>{</b>
        <font color='#0000FF'>using</font> <font color='#0000FF'>namespace</font> open_file_box_helper;
        box_win<font color='#5555FF'>*</font> win <font color='#5555FF'>=</font> <font color='#0000FF'>new</font> <font color='#BB00BB'>box_win</font><font face='Lucida Console'>(</font>"<font color='#CC0000'>Save File</font>",<font color='#979000'>true</font><font face='Lucida Console'>)</font>;
        win<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font><font color='#BB00BB'>set_click_handler</font><font face='Lucida Console'>(</font><font color='#BB00BB'>make_mfp</font><font face='Lucida Console'>(</font>object,event_handler<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
    <b>}</b>

    <font color='#0000FF'>inline</font> <font color='#0000FF'><u>void</u></font> <b><a name='save_file_box'></a>save_file_box</b> <font face='Lucida Console'>(</font>
        <font color='#0000FF'>const</font> any_function<font color='#5555FF'>&lt;</font><font color='#0000FF'><u>void</u></font><font face='Lucida Console'>(</font><font color='#0000FF'>const</font> std::string<font color='#5555FF'>&amp;</font><font face='Lucida Console'>)</font><font color='#5555FF'>&gt;</font><font color='#5555FF'>&amp;</font> event_handler
    <font face='Lucida Console'>)</font>
    <b>{</b>
        <font color='#0000FF'>using</font> <font color='#0000FF'>namespace</font> open_file_box_helper;
        box_win<font color='#5555FF'>*</font> win <font color='#5555FF'>=</font> <font color='#0000FF'>new</font> <font color='#BB00BB'>box_win</font><font face='Lucida Console'>(</font>"<font color='#CC0000'>Save File</font>",<font color='#979000'>true</font><font face='Lucida Console'>)</font>;
        win<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font><font color='#BB00BB'>set_click_handler</font><font face='Lucida Console'>(</font>event_handler<font face='Lucida Console'>)</font>;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font><font color='#009900'>// ----------------------------------------------------------------------------------------
</font>    <font color='#009900'>// class menu_bar
</font><font color='#009900'>// ----------------------------------------------------------------------------------------
</font><font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'>class</font> <b><a name='menu_bar'></a>menu_bar</b> : <font color='#0000FF'>public</font> drawable
    <b>{</b>
        <font color='#009900'>/*!
            INITIAL VALUE
                - menus.size() == 0
                - open_menu == 0 

            CONVENTION 
                - size() == menus.size() 
                - all menu data is stored in menus
                - menus[x].name == the name of the xth menu
                - if (menus[x].underline_pos != std::string::npos) then
                    - menus[x].underline_pos == the position of the character in the
                      menu name that should be underlined
                    - menus[x].underline_p1 != menus[x].underline_p2
                      and these two points define the underline bar
                - else
                    - menus[x].underline_p1 == menus[x].underline_p2
                - menus[x].menu == menu(x)
                - menus[x].rect == the rectangle in which menus[x].name is drawn
                - menus[x].bgrect == the rectangle for the xth menu button

                - if (there is an open menu on the screen) then
                    - open_menu == the index of the open menu from menus 
                - else
                    - open_menu == menus.size() 
        !*/</font>

    <font color='#0000FF'>public</font>:
        <b><a name='menu_bar'></a>menu_bar</b><font face='Lucida Console'>(</font>
            drawable_window<font color='#5555FF'>&amp;</font> w
        <font face='Lucida Console'>)</font>;

        ~<b><a name='menu_bar'></a>menu_bar</b><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;

        <font color='#009900'>// this function does nothing
</font>        <font color='#0000FF'><u>void</u></font> <b><a name='set_pos'></a>set_pos</b><font face='Lucida Console'>(</font><font color='#0000FF'><u>long</u></font>,<font color='#0000FF'><u>long</u></font><font face='Lucida Console'>)</font><b>{</b><b>}</b>

        <font color='#0000FF'><u>void</u></font> <b><a name='set_main_font'></a>set_main_font</b> <font face='Lucida Console'>(</font>
            <font color='#0000FF'>const</font> shared_ptr_thread_safe<font color='#5555FF'>&lt;</font>font<font color='#5555FF'>&gt;</font><font color='#5555FF'>&amp;</font> f
        <font face='Lucida Console'>)</font>;

        <font color='#0000FF'><u>void</u></font> <b><a name='set_number_of_menus'></a>set_number_of_menus</b> <font face='Lucida Console'>(</font>
            <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> num
        <font face='Lucida Console'>)</font>;

        <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> <b><a name='number_of_menus'></a>number_of_menus</b> <font face='Lucida Console'>(</font>
        <font face='Lucida Console'>)</font> <font color='#0000FF'>const</font>;

        <font color='#0000FF'><u>void</u></font> <b><a name='set_menu_name'></a>set_menu_name</b> <font face='Lucida Console'>(</font>
            <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> idx,
            <font color='#0000FF'>const</font> std::string name,
            <font color='#0000FF'><u>char</u></font> underline_ch <font color='#5555FF'>=</font> '<font color='#FF0000'>\0</font>'
        <font face='Lucida Console'>)</font>;

        <font color='#0000FF'><u>void</u></font> <b><a name='set_menu_name'></a>set_menu_name</b> <font face='Lucida Console'>(</font>
            <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> idx,
            <font color='#0000FF'>const</font> std::wstring name,
            <font color='#0000FF'><u>char</u></font> underline_ch <font color='#5555FF'>=</font> '<font color='#FF0000'>\0</font>'
        <font face='Lucida Console'>)</font>;

        <font color='#0000FF'><u>void</u></font> <b><a name='set_menu_name'></a>set_menu_name</b> <font face='Lucida Console'>(</font>
            <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> idx,
            <font color='#0000FF'>const</font> dlib::ustring name,
            <font color='#0000FF'><u>char</u></font> underline_ch <font color='#5555FF'>=</font> '<font color='#FF0000'>\0</font>'
        <font face='Lucida Console'>)</font>;

        <font color='#0000FF'>const</font> std::string <b><a name='menu_name'></a>menu_name</b> <font face='Lucida Console'>(</font>
            <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> idx
        <font face='Lucida Console'>)</font> <font color='#0000FF'>const</font>;

        <font color='#0000FF'>const</font> std::wstring <b><a name='menu_wname'></a>menu_wname</b> <font face='Lucida Console'>(</font>
            <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> idx
        <font face='Lucida Console'>)</font> <font color='#0000FF'>const</font>;

        <font color='#0000FF'>const</font> dlib::ustring <b><a name='menu_uname'></a>menu_uname</b> <font face='Lucida Console'>(</font>
            <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> idx
        <font face='Lucida Console'>)</font> <font color='#0000FF'>const</font>;

        popup_menu<font color='#5555FF'>&amp;</font> <b><a name='menu'></a>menu</b> <font face='Lucida Console'>(</font>
            <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> idx
        <font face='Lucida Console'>)</font>;

        <font color='#0000FF'>const</font> popup_menu<font color='#5555FF'>&amp;</font> <b><a name='menu'></a>menu</b> <font face='Lucida Console'>(</font>
            <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> idx
        <font face='Lucida Console'>)</font> <font color='#0000FF'>const</font>;

    <font color='#0000FF'>protected</font>:

        <font color='#0000FF'><u>void</u></font> <b><a name='on_window_resized'></a>on_window_resized</b> <font face='Lucida Console'>(</font>
        <font face='Lucida Console'>)</font>;

        <font color='#0000FF'><u>void</u></font> <b><a name='draw'></a>draw</b> <font face='Lucida Console'>(</font>
            <font color='#0000FF'>const</font> canvas<font color='#5555FF'>&amp;</font> c
        <font face='Lucida Console'>)</font> <font color='#0000FF'>const</font>;

        <font color='#0000FF'><u>void</u></font> <b><a name='on_window_moved'></a>on_window_moved</b> <font face='Lucida Console'>(</font>
        <font face='Lucida Console'>)</font>;

        <font color='#0000FF'><u>void</u></font> <b><a name='on_focus_lost'></a>on_focus_lost</b> <font face='Lucida Console'>(</font>
        <font face='Lucida Console'>)</font>;

        <font color='#0000FF'><u>void</u></font> <b><a name='on_mouse_down'></a>on_mouse_down</b> <font face='Lucida Console'>(</font>
            <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> btn,
            <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> ,
            <font color='#0000FF'><u>long</u></font> x,
            <font color='#0000FF'><u>long</u></font> y,
            <font color='#0000FF'><u>bool</u></font> 
        <font face='Lucida Console'>)</font>;

        <font color='#0000FF'><u>void</u></font> <b><a name='on_mouse_move'></a>on_mouse_move</b> <font face='Lucida Console'>(</font>
            <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> ,
            <font color='#0000FF'><u>long</u></font> x,
            <font color='#0000FF'><u>long</u></font> y
        <font face='Lucida Console'>)</font>;

        <font color='#0000FF'><u>void</u></font> <b><a name='on_keydown'></a>on_keydown</b> <font face='Lucida Console'>(</font>
            <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> key,
            <font color='#0000FF'><u>bool</u></font> is_printable,
            <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> state
        <font face='Lucida Console'>)</font>;

    <font color='#0000FF'>private</font>:

        <font color='#0000FF'><u>void</u></font> <b><a name='show_menu'></a>show_menu</b> <font face='Lucida Console'>(</font>
            <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> i
        <font face='Lucida Console'>)</font>;

        <font color='#0000FF'><u>void</u></font> <b><a name='hide_menu'></a>hide_menu</b> <font face='Lucida Console'>(</font>
        <font face='Lucida Console'>)</font>;

        <font color='#0000FF'><u>void</u></font> <b><a name='on_popup_hide'></a>on_popup_hide</b> <font face='Lucida Console'>(</font>
        <font face='Lucida Console'>)</font>;

        <font color='#0000FF'><u>void</u></font> <b><a name='compute_menu_geometry'></a>compute_menu_geometry</b> <font face='Lucida Console'>(</font>
        <font face='Lucida Console'>)</font>;

        <font color='#0000FF'><u>void</u></font> <b><a name='adjust_position'></a>adjust_position</b> <font face='Lucida Console'>(</font>
        <font face='Lucida Console'>)</font>;

        <font color='#0000FF'>struct</font> <b><a name='menu_data'></a>menu_data</b>
        <b>{</b>
            <b><a name='menu_data'></a>menu_data</b><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>:underline_pos<font face='Lucida Console'>(</font>dlib::ustring::npos<font face='Lucida Console'>)</font><b>{</b><b>}</b>

            dlib::ustring name;
            dlib::ustring::size_type underline_pos;
            popup_menu menu;
            rectangle rect;
            rectangle bgrect;
            point underline_p1;
            point underline_p2;
        <b>}</b>;

        array<font color='#5555FF'>&lt;</font>menu_data<font color='#5555FF'>&gt;</font> menus;
        <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> open_menu;

        <font color='#009900'>// restricted functions
</font>        <b><a name='menu_bar'></a>menu_bar</b><font face='Lucida Console'>(</font>menu_bar<font color='#5555FF'>&amp;</font><font face='Lucida Console'>)</font>;        <font color='#009900'>// copy constructor
</font>        menu_bar<font color='#5555FF'>&amp;</font> <b><a name='operator'></a>operator</b><font color='#5555FF'>=</font><font face='Lucida Console'>(</font>menu_bar<font color='#5555FF'>&amp;</font><font face='Lucida Console'>)</font>;    <font color='#009900'>// assignment operator
</font>
    <b>}</b>;

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font><font color='#009900'>// ----------------------------------------------------------------------------------------
</font>    <font color='#009900'>// class directed_graph_drawer
</font><font color='#009900'>// ----------------------------------------------------------------------------------------
</font><font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'>template</font> <font color='#5555FF'>&lt;</font><font color='#0000FF'>typename</font> graph_type<font color='#5555FF'>&gt;</font>
    <font color='#0000FF'>class</font> <b><a name='directed_graph_drawer'></a>directed_graph_drawer</b> : <font color='#0000FF'>public</font> zoomable_region 
    <b>{</b>
        <font color='#009900'>/*!
            INITIAL VALUE
                - edge_selected == false
                - mouse_drag == false
                - selected_node == 0
                - graph_.number_of_nodes() == 0
                - external_graph.number_of_nodes() == 0
                - radius == 25
                - last_mouse_click_in_display == false

            CONVENTION
                - radius == the radius of the nodes when they aren't zoomed
                - external_graph and graph_ have the same graph structure
                - external_graph == graph()
                - external_graph.node(i) == graph_node(i)

                - if (one of the nodes is selected) then
                    - selected_node &lt; graph_.number_of_nodes()
                    - graph_.node(selected_node) == the selected node
                - else
                    - selected_node == graph_.number_of_nodes()

                - if (the user is dragging a node with the mouse) then
                    - mouse_drag == true
                    - drag_offset == the vector from the mouse position to the
                      center of the node
                - else
                    - mouse_drag == false

                - if (the user has selected an edge) then
                    - edge_selected == true
                    - the parent node is graph_.node(selected_edge_parent)
                    - the child node is graph_.node(selected_edge_parent)
                - else
                    - edge_selected == false

                - for all valid i:
                    - graph_.node(i).data.p == the center of the node in graph space
                    - graph_.node(i).data.name == node_label(i) 
                    - graph_.node(i).data.color == node_color(i) 
                    - graph_.node(i).data.str_rect == a rectangle sized to contain graph_.node(i).data.name

                - if (the last mouse click in our parent window as in our display_rect_ ) then
                    - last_mouse_click_in_display == true
                - else
                    - last_mouse_click_in_display == false
        !*/</font>

    <font color='#0000FF'>public</font>:
        <b><a name='directed_graph_drawer'></a>directed_graph_drawer</b> <font face='Lucida Console'>(</font>
            drawable_window<font color='#5555FF'>&amp;</font> w
        <font face='Lucida Console'>)</font> :
            zoomable_region<font face='Lucida Console'>(</font>w,MOUSE_CLICK <font color='#5555FF'>|</font> MOUSE_WHEEL <font color='#5555FF'>|</font> KEYBOARD_EVENTS<font face='Lucida Console'>)</font>,
            radius<font face='Lucida Console'>(</font><font color='#979000'>25</font><font face='Lucida Console'>)</font>,
            edge_selected<font face='Lucida Console'>(</font><font color='#979000'>false</font><font face='Lucida Console'>)</font>,
            last_mouse_click_in_display<font face='Lucida Console'>(</font><font color='#979000'>false</font><font face='Lucida Console'>)</font>
        <b>{</b>
            mouse_drag <font color='#5555FF'>=</font> <font color='#979000'>false</font>;
            selected_node <font color='#5555FF'>=</font> <font color='#979000'>0</font>;

            <font color='#009900'>// Whenever you make your own drawable (or inherit from draggable or button_action)
</font>            <font color='#009900'>// you have to remember to call this function to enable the events.  The idea
</font>            <font color='#009900'>// here is that you can perform whatever setup you need to do to get your 
</font>            <font color='#009900'>// object into a valid state without needing to worry about event handlers 
</font>            <font color='#009900'>// triggering before you are ready.
</font>            <font color='#BB00BB'>enable_events</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
        <b>}</b>

        ~<b><a name='directed_graph_drawer'></a>directed_graph_drawer</b> <font face='Lucida Console'>(</font>
        <font face='Lucida Console'>)</font>
        <b>{</b>
            <font color='#009900'>// Disable all further events for this drawable object.  We have to do this 
</font>            <font color='#009900'>// because we don't want draw() events coming to this object while or after 
</font>            <font color='#009900'>// it has been destructed.
</font>            <font color='#BB00BB'>disable_events</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;

            <font color='#009900'>// Tell the parent window to redraw its area that previously contained this
</font>            <font color='#009900'>// drawable object.
</font>            parent.<font color='#BB00BB'>invalidate_rectangle</font><font face='Lucida Console'>(</font>rect<font face='Lucida Console'>)</font>;
        <b>}</b>

        <font color='#0000FF'><u>void</u></font> <b><a name='clear_graph'></a>clear_graph</b> <font face='Lucida Console'>(</font>
        <font face='Lucida Console'>)</font>
        <b>{</b>
            auto_mutex <font color='#BB00BB'>M</font><font face='Lucida Console'>(</font>m<font face='Lucida Console'>)</font>;
            graph_.<font color='#BB00BB'>clear</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
            external_graph.<font color='#BB00BB'>clear</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
            parent.<font color='#BB00BB'>invalidate_rectangle</font><font face='Lucida Console'>(</font><font color='#BB00BB'>display_rect</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
        <b>}</b>

        <font color='#0000FF'>const</font> <font color='#0000FF'>typename</font> graph_type::node_type<font color='#5555FF'>&amp;</font> <b><a name='graph_node'></a>graph_node</b> <font face='Lucida Console'>(</font>
            <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> i
        <font face='Lucida Console'>)</font>  <font color='#0000FF'>const</font>
        <b>{</b>
            <font color='#BB00BB'>DLIB_ASSERT</font> <font face='Lucida Console'>(</font> i <font color='#5555FF'>&lt;</font> <font color='#BB00BB'>number_of_nodes</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> ,
                    "<font color='#CC0000'>\tgraph_type::node_type&amp; directed_graph_drawer::graph_node(i)</font>"
                    <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>\n\ti:                 </font>" <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> i 
                    <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>\n\tnumber_of_nodes(): </font>" <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> <font color='#BB00BB'>number_of_nodes</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> 
                    <font face='Lucida Console'>)</font>;
            <font color='#0000FF'>return</font> external_graph.<font color='#BB00BB'>node</font><font face='Lucida Console'>(</font>i<font face='Lucida Console'>)</font>;
        <b>}</b>

        <font color='#0000FF'>typename</font> graph_type::node_type<font color='#5555FF'>&amp;</font> <b><a name='graph_node'></a>graph_node</b> <font face='Lucida Console'>(</font>
            <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> i
        <font face='Lucida Console'>)</font> 
        <b>{</b>
            <font color='#BB00BB'>DLIB_ASSERT</font> <font face='Lucida Console'>(</font> i <font color='#5555FF'>&lt;</font> <font color='#BB00BB'>number_of_nodes</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> ,
                    "<font color='#CC0000'>\tgraph_type::node_type&amp; directed_graph_drawer::graph_node(i)</font>"
                    <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>\n\ti:                 </font>" <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> i 
                    <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>\n\tnumber_of_nodes(): </font>" <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> <font color='#BB00BB'>number_of_nodes</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> 
                    <font face='Lucida Console'>)</font>;
            <font color='#0000FF'>return</font> external_graph.<font color='#BB00BB'>node</font><font face='Lucida Console'>(</font>i<font face='Lucida Console'>)</font>;
        <b>}</b>

        <font color='#0000FF'>const</font> graph_type<font color='#5555FF'>&amp;</font> <b><a name='graph'></a>graph</b> <font face='Lucida Console'>(</font>
        <font face='Lucida Console'>)</font> <font color='#0000FF'>const</font>
        <b>{</b>
            <font color='#0000FF'>return</font> external_graph;
        <b>}</b>

        <font color='#0000FF'><u>void</u></font> <b><a name='save_graph'></a>save_graph</b> <font face='Lucida Console'>(</font>
            std::ostream<font color='#5555FF'>&amp;</font> out
        <font face='Lucida Console'>)</font>
        <b>{</b>
            auto_mutex <font color='#BB00BB'>M</font><font face='Lucida Console'>(</font>m<font face='Lucida Console'>)</font>;
            <font color='#BB00BB'>serialize</font><font face='Lucida Console'>(</font>external_graph, out<font face='Lucida Console'>)</font>;
            <font color='#BB00BB'>serialize</font><font face='Lucida Console'>(</font>graph_, out<font face='Lucida Console'>)</font>;
            parent.<font color='#BB00BB'>invalidate_rectangle</font><font face='Lucida Console'>(</font><font color='#BB00BB'>display_rect</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
        <b>}</b>

        <font color='#0000FF'><u>void</u></font> <b><a name='load_graph'></a>load_graph</b> <font face='Lucida Console'>(</font>
            std::istream<font color='#5555FF'>&amp;</font> in 
        <font face='Lucida Console'>)</font>
        <b>{</b>
            auto_mutex <font color='#BB00BB'>M</font><font face='Lucida Console'>(</font>m<font face='Lucida Console'>)</font>;
            <font color='#BB00BB'>deserialize</font><font face='Lucida Console'>(</font>external_graph, in<font face='Lucida Console'>)</font>;
            <font color='#BB00BB'>deserialize</font><font face='Lucida Console'>(</font>graph_, in<font face='Lucida Console'>)</font>;
            parent.<font color='#BB00BB'>invalidate_rectangle</font><font face='Lucida Console'>(</font><font color='#BB00BB'>display_rect</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
        <b>}</b>

        <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> <b><a name='number_of_nodes'></a>number_of_nodes</b> <font face='Lucida Console'>(</font>
        <font face='Lucida Console'>)</font> <font color='#0000FF'>const</font>
        <b>{</b>
            auto_mutex <font color='#BB00BB'>M</font><font face='Lucida Console'>(</font>m<font face='Lucida Console'>)</font>;
            <font color='#0000FF'>return</font> graph_.<font color='#BB00BB'>number_of_nodes</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
        <b>}</b>

        <font color='#0000FF'><u>void</u></font> <b><a name='set_node_label'></a>set_node_label</b> <font face='Lucida Console'>(</font>
            <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> i,
            <font color='#0000FF'>const</font> std::string<font color='#5555FF'>&amp;</font> label
        <font face='Lucida Console'>)</font>
        <b>{</b>
            <font color='#BB00BB'>set_node_label</font><font face='Lucida Console'>(</font>i, <font color='#BB00BB'>convert_mbstring_to_wstring</font><font face='Lucida Console'>(</font>label<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
        <b>}</b>

        <font color='#0000FF'><u>void</u></font> <b><a name='set_node_label'></a>set_node_label</b> <font face='Lucida Console'>(</font>
            <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> i,
            <font color='#0000FF'>const</font> std::wstring<font color='#5555FF'>&amp;</font> label
        <font face='Lucida Console'>)</font>
        <b>{</b>
            <font color='#BB00BB'>set_node_label</font><font face='Lucida Console'>(</font>i, <font color='#BB00BB'>convert_wstring_to_utf32</font><font face='Lucida Console'>(</font>label<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
        <b>}</b>

        <font color='#0000FF'><u>void</u></font> <b><a name='set_node_label'></a>set_node_label</b> <font face='Lucida Console'>(</font>
            <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> i,
            <font color='#0000FF'>const</font> dlib::ustring<font color='#5555FF'>&amp;</font> label
        <font face='Lucida Console'>)</font>
        <b>{</b>
            auto_mutex <font color='#BB00BB'>M</font><font face='Lucida Console'>(</font>m<font face='Lucida Console'>)</font>;
            <font color='#BB00BB'>DLIB_ASSERT</font> <font face='Lucida Console'>(</font> i <font color='#5555FF'>&lt;</font> <font color='#BB00BB'>number_of_nodes</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> ,
                    "<font color='#CC0000'>\tvoid directed_graph_drawer::set_node_label(i,label)</font>"
                    <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>\n\ti:                 </font>" <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> i 
                    <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>\n\tlabel:             </font>" <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> <font color='#BB00BB'>narrow</font><font face='Lucida Console'>(</font>label<font face='Lucida Console'>)</font> 
                    <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>\n\tnumber_of_nodes(): </font>" <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> <font color='#BB00BB'>number_of_nodes</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> 
                    <font face='Lucida Console'>)</font>;
            graph_.<font color='#BB00BB'>node</font><font face='Lucida Console'>(</font>i<font face='Lucida Console'>)</font>.data.name <font color='#5555FF'>=</font> label.<font color='#BB00BB'>c_str</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
            <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> width, height;
            mfont<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font><font color='#BB00BB'>compute_size</font><font face='Lucida Console'>(</font>label,width,height<font face='Lucida Console'>)</font>;
            graph_.<font color='#BB00BB'>node</font><font face='Lucida Console'>(</font>i<font face='Lucida Console'>)</font>.data.str_rect <font color='#5555FF'>=</font> <font color='#BB00BB'>rectangle</font><font face='Lucida Console'>(</font>width,height<font face='Lucida Console'>)</font>;
            parent.<font color='#BB00BB'>invalidate_rectangle</font><font face='Lucida Console'>(</font><font color='#BB00BB'>display_rect</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
        <b>}</b>

        <font color='#0000FF'><u>void</u></font> <b><a name='set_node_color'></a>set_node_color</b> <font face='Lucida Console'>(</font>
            <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> i,
            rgb_pixel color
        <font face='Lucida Console'>)</font>
        <b>{</b>
            auto_mutex <font color='#BB00BB'>M</font><font face='Lucida Console'>(</font>m<font face='Lucida Console'>)</font>;
            <font color='#BB00BB'>DLIB_ASSERT</font> <font face='Lucida Console'>(</font> i <font color='#5555FF'>&lt;</font> <font color='#BB00BB'>number_of_nodes</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> ,
                    "<font color='#CC0000'>\tvoid directed_graph_drawer::set_node_color(i,label)</font>"
                    <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>\n\ti:                 </font>" <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> i 
                    <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>\n\tnumber_of_nodes(): </font>" <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> <font color='#BB00BB'>number_of_nodes</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> 
                    <font face='Lucida Console'>)</font>;
            graph_.<font color='#BB00BB'>node</font><font face='Lucida Console'>(</font>i<font face='Lucida Console'>)</font>.data.color <font color='#5555FF'>=</font> color;
            parent.<font color='#BB00BB'>invalidate_rectangle</font><font face='Lucida Console'>(</font><font color='#BB00BB'>display_rect</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
        <b>}</b>

        rgb_pixel <b><a name='node_color'></a>node_color</b> <font face='Lucida Console'>(</font>
            <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> i
        <font face='Lucida Console'>)</font> <font color='#0000FF'>const</font>
        <b>{</b>
            auto_mutex <font color='#BB00BB'>M</font><font face='Lucida Console'>(</font>m<font face='Lucida Console'>)</font>;
            <font color='#BB00BB'>DLIB_ASSERT</font> <font face='Lucida Console'>(</font> i <font color='#5555FF'>&lt;</font> <font color='#BB00BB'>number_of_nodes</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> ,
                    "<font color='#CC0000'>\trgb_pixel directed_graph_drawer::node_color(i)</font>"
                    <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>\n\ti:                 </font>" <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> i 
                    <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>\n\tnumber_of_nodes(): </font>" <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> <font color='#BB00BB'>number_of_nodes</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> 
                    <font face='Lucida Console'>)</font>;
            <font color='#0000FF'>return</font> graph_.<font color='#BB00BB'>node</font><font face='Lucida Console'>(</font>i<font face='Lucida Console'>)</font>.data.color;
        <b>}</b>

        <font color='#0000FF'>const</font> std::string <b><a name='node_label'></a>node_label</b> <font face='Lucida Console'>(</font>
            <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> i
        <font face='Lucida Console'>)</font> <font color='#0000FF'>const</font>
        <b>{</b>
            auto_mutex <font color='#BB00BB'>M</font><font face='Lucida Console'>(</font>m<font face='Lucida Console'>)</font>;
            <font color='#BB00BB'>DLIB_ASSERT</font> <font face='Lucida Console'>(</font> i <font color='#5555FF'>&lt;</font> <font color='#BB00BB'>number_of_nodes</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> ,
                    "<font color='#CC0000'>\tconst std::ustring directed_graph_drawer::node_label(i)</font>"
                    <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>\n\ti:                 </font>" <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> i 
                    <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>\n\tnumber_of_nodes(): </font>" <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> <font color='#BB00BB'>number_of_nodes</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> 
                    <font face='Lucida Console'>)</font>;
            <font color='#0000FF'>return</font> <font color='#BB00BB'>narrow</font><font face='Lucida Console'>(</font>graph_.<font color='#BB00BB'>node</font><font face='Lucida Console'>(</font>i<font face='Lucida Console'>)</font>.data.name<font face='Lucida Console'>)</font>;
        <b>}</b>

        <font color='#0000FF'>const</font> std::wstring <b><a name='node_wlabel'></a>node_wlabel</b> <font face='Lucida Console'>(</font>
            <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> i
        <font face='Lucida Console'>)</font> <font color='#0000FF'>const</font>
        <b>{</b>
            <font color='#0000FF'>return</font> <font color='#BB00BB'>convert_utf32_to_wstring</font><font face='Lucida Console'>(</font><font color='#BB00BB'>node_ulabel</font><font face='Lucida Console'>(</font>i<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
        <b>}</b>

        <font color='#0000FF'>const</font> dlib::ustring <b><a name='node_ulabel'></a>node_ulabel</b> <font face='Lucida Console'>(</font>
            <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> i
        <font face='Lucida Console'>)</font> <font color='#0000FF'>const</font>
        <b>{</b>
            auto_mutex <font color='#BB00BB'>M</font><font face='Lucida Console'>(</font>m<font face='Lucida Console'>)</font>;
            <font color='#BB00BB'>DLIB_ASSERT</font> <font face='Lucida Console'>(</font> i <font color='#5555FF'>&lt;</font> <font color='#BB00BB'>number_of_nodes</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> ,
                    "<font color='#CC0000'>\tconst std::ustring directed_graph_drawer::node_label(i)</font>"
                    <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>\n\ti:                 </font>" <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> i 
                    <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>\n\tnumber_of_nodes(): </font>" <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> <font color='#BB00BB'>number_of_nodes</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> 
                    <font face='Lucida Console'>)</font>;
            <font color='#0000FF'>return</font> graph_.<font color='#BB00BB'>node</font><font face='Lucida Console'>(</font>i<font face='Lucida Console'>)</font>.data.name.<font color='#BB00BB'>c_str</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
        <b>}</b>

        <font color='#0000FF'>template</font> <font color='#5555FF'>&lt;</font>
            <font color='#0000FF'>typename</font> T
            <font color='#5555FF'>&gt;</font>
        <font color='#0000FF'><u>void</u></font> <b><a name='set_node_selected_handler'></a>set_node_selected_handler</b> <font face='Lucida Console'>(</font>
            T<font color='#5555FF'>&amp;</font> object,
            <font color='#0000FF'><u>void</u></font> <font face='Lucida Console'>(</font>T::<font color='#5555FF'>*</font>event_handler_<font face='Lucida Console'>)</font><font face='Lucida Console'>(</font><font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font><font face='Lucida Console'>)</font>
        <font face='Lucida Console'>)</font>
        <b>{</b>
            auto_mutex <font color='#BB00BB'>M</font><font face='Lucida Console'>(</font>m<font face='Lucida Console'>)</font>;
            node_selected_handler <font color='#5555FF'>=</font> <font color='#BB00BB'>make_mfp</font><font face='Lucida Console'>(</font>object,event_handler_<font face='Lucida Console'>)</font>;
        <b>}</b>

        <font color='#0000FF'><u>void</u></font> <b><a name='set_node_selected_handler'></a>set_node_selected_handler</b> <font face='Lucida Console'>(</font>
            <font color='#0000FF'>const</font> any_function<font color='#5555FF'>&lt;</font><font color='#0000FF'><u>void</u></font><font face='Lucida Console'>(</font><font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font><font face='Lucida Console'>)</font><font color='#5555FF'>&gt;</font><font color='#5555FF'>&amp;</font> event_handler_
        <font face='Lucida Console'>)</font>
        <b>{</b>
            auto_mutex <font color='#BB00BB'>M</font><font face='Lucida Console'>(</font>m<font face='Lucida Console'>)</font>;
            node_selected_handler <font color='#5555FF'>=</font> event_handler_;
        <b>}</b>

        <font color='#0000FF'>template</font> <font color='#5555FF'>&lt;</font>
            <font color='#0000FF'>typename</font> T
            <font color='#5555FF'>&gt;</font>
        <font color='#0000FF'><u>void</u></font> <b><a name='set_node_deselected_handler'></a>set_node_deselected_handler</b> <font face='Lucida Console'>(</font>
            T<font color='#5555FF'>&amp;</font> object,
            <font color='#0000FF'><u>void</u></font> <font face='Lucida Console'>(</font>T::<font color='#5555FF'>*</font>event_handler_<font face='Lucida Console'>)</font><font face='Lucida Console'>(</font><font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font><font face='Lucida Console'>)</font>
        <font face='Lucida Console'>)</font>
        <b>{</b>
            auto_mutex <font color='#BB00BB'>M</font><font face='Lucida Console'>(</font>m<font face='Lucida Console'>)</font>;
            node_deselected_handler <font color='#5555FF'>=</font> <font color='#BB00BB'>make_mfp</font><font face='Lucida Console'>(</font>object,event_handler_<font face='Lucida Console'>)</font>;
        <b>}</b>

        <font color='#0000FF'><u>void</u></font> <b><a name='set_node_deselected_handler'></a>set_node_deselected_handler</b> <font face='Lucida Console'>(</font>
            <font color='#0000FF'>const</font> any_function<font color='#5555FF'>&lt;</font><font color='#0000FF'><u>void</u></font><font face='Lucida Console'>(</font><font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font><font face='Lucida Console'>)</font><font color='#5555FF'>&gt;</font><font color='#5555FF'>&amp;</font> event_handler_
        <font face='Lucida Console'>)</font>
        <b>{</b>
            auto_mutex <font color='#BB00BB'>M</font><font face='Lucida Console'>(</font>m<font face='Lucida Console'>)</font>;
            node_deselected_handler <font color='#5555FF'>=</font> event_handler_;
        <b>}</b>

        <font color='#0000FF'>template</font> <font color='#5555FF'>&lt;</font>
            <font color='#0000FF'>typename</font> T
            <font color='#5555FF'>&gt;</font>
        <font color='#0000FF'><u>void</u></font> <b><a name='set_node_deleted_handler'></a>set_node_deleted_handler</b> <font face='Lucida Console'>(</font>
            T<font color='#5555FF'>&amp;</font> object,
            <font color='#0000FF'><u>void</u></font> <font face='Lucida Console'>(</font>T::<font color='#5555FF'>*</font>event_handler_<font face='Lucida Console'>)</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>
        <font face='Lucida Console'>)</font>
        <b>{</b>
            auto_mutex <font color='#BB00BB'>M</font><font face='Lucida Console'>(</font>m<font face='Lucida Console'>)</font>;
            node_deleted_handler <font color='#5555FF'>=</font> <font color='#BB00BB'>make_mfp</font><font face='Lucida Console'>(</font>object,event_handler_<font face='Lucida Console'>)</font>;
        <b>}</b>

        <font color='#0000FF'><u>void</u></font> <b><a name='set_node_deleted_handler'></a>set_node_deleted_handler</b> <font face='Lucida Console'>(</font>
            <font color='#0000FF'>const</font> any_function<font color='#5555FF'>&lt;</font><font color='#0000FF'><u>void</u></font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>&gt;</font><font color='#5555FF'>&amp;</font> event_handler_
        <font face='Lucida Console'>)</font>
        <b>{</b>
            auto_mutex <font color='#BB00BB'>M</font><font face='Lucida Console'>(</font>m<font face='Lucida Console'>)</font>;
            node_deleted_handler <font color='#5555FF'>=</font> event_handler_;
        <b>}</b>

        <font color='#0000FF'>template</font> <font color='#5555FF'>&lt;</font>
            <font color='#0000FF'>typename</font> T
            <font color='#5555FF'>&gt;</font>
        <font color='#0000FF'><u>void</u></font> <b><a name='set_graph_modified_handler'></a>set_graph_modified_handler</b> <font face='Lucida Console'>(</font>
            T<font color='#5555FF'>&amp;</font> object,
            <font color='#0000FF'><u>void</u></font> <font face='Lucida Console'>(</font>T::<font color='#5555FF'>*</font>event_handler_<font face='Lucida Console'>)</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>
        <font face='Lucida Console'>)</font>
        <b>{</b>
            auto_mutex <font color='#BB00BB'>M</font><font face='Lucida Console'>(</font>m<font face='Lucida Console'>)</font>;
            graph_modified_handler <font color='#5555FF'>=</font> <font color='#BB00BB'>make_mfp</font><font face='Lucida Console'>(</font>object,event_handler_<font face='Lucida Console'>)</font>;
        <b>}</b>

        <font color='#0000FF'><u>void</u></font> <b><a name='set_graph_modified_handler'></a>set_graph_modified_handler</b> <font face='Lucida Console'>(</font>
            <font color='#0000FF'>const</font> any_function<font color='#5555FF'>&lt;</font><font color='#0000FF'><u>void</u></font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>&gt;</font><font color='#5555FF'>&amp;</font> event_handler_
        <font face='Lucida Console'>)</font>
        <b>{</b>
            auto_mutex <font color='#BB00BB'>M</font><font face='Lucida Console'>(</font>m<font face='Lucida Console'>)</font>;
            graph_modified_handler <font color='#5555FF'>=</font> event_handler_;
        <b>}</b>

    <font color='#0000FF'>protected</font>:

        <font color='#0000FF'><u>void</u></font> <b><a name='on_keydown'></a>on_keydown</b> <font face='Lucida Console'>(</font>
            <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> key,          
            <font color='#0000FF'><u>bool</u></font> ,
            <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> 
        <font face='Lucida Console'>)</font>
        <b>{</b>
            <font color='#009900'>// ignore all keyboard input if the last thing the user clicked on 
</font>            <font color='#009900'>// wasn't the display area
</font>            <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>last_mouse_click_in_display <font color='#5555FF'>=</font><font color='#5555FF'>=</font> <font color='#979000'>false</font><font face='Lucida Console'>)</font>
                <font color='#0000FF'>return</font>;

            <font color='#009900'>// if a node is selected
</font>            <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>selected_node <font color='#5555FF'>!</font><font color='#5555FF'>=</font> graph_.<font color='#BB00BB'>number_of_nodes</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>
            <b>{</b>
                <font color='#009900'>// deselect the node if the user hits escape
</font>                <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>key <font color='#5555FF'>=</font><font color='#5555FF'>=</font> base_window::KEY_ESC<font face='Lucida Console'>)</font>
                <b>{</b>
                    parent.<font color='#BB00BB'>invalidate_rectangle</font><font face='Lucida Console'>(</font><font color='#BB00BB'>display_rect</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
                    <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>node_deselected_handler.<font color='#BB00BB'>is_set</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>
                        <font color='#BB00BB'>node_deselected_handler</font><font face='Lucida Console'>(</font>selected_node<font face='Lucida Console'>)</font>;
                    selected_node <font color='#5555FF'>=</font> graph_.<font color='#BB00BB'>number_of_nodes</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
                <b>}</b>

                <font color='#009900'>// delete the node if the user hits delete 
</font>                <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>key <font color='#5555FF'>=</font><font color='#5555FF'>=</font> base_window::KEY_DELETE <font color='#5555FF'>|</font><font color='#5555FF'>|</font> key <font color='#5555FF'>=</font><font color='#5555FF'>=</font> base_window::KEY_BACKSPACE<font face='Lucida Console'>)</font>
                <b>{</b>
                    parent.<font color='#BB00BB'>invalidate_rectangle</font><font face='Lucida Console'>(</font><font color='#BB00BB'>display_rect</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
                    graph_.<font color='#BB00BB'>remove_node</font><font face='Lucida Console'>(</font>selected_node<font face='Lucida Console'>)</font>;
                    external_graph.<font color='#BB00BB'>remove_node</font><font face='Lucida Console'>(</font>selected_node<font face='Lucida Console'>)</font>;
                    selected_node <font color='#5555FF'>=</font> graph_.<font color='#BB00BB'>number_of_nodes</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
                    mouse_drag <font color='#5555FF'>=</font> <font color='#979000'>false</font>;
                    <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>graph_modified_handler.<font color='#BB00BB'>is_set</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>
                        <font color='#BB00BB'>graph_modified_handler</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
                    <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>node_deleted_handler.<font color='#BB00BB'>is_set</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>
                        <font color='#BB00BB'>node_deleted_handler</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
                <b>}</b>
            <b>}</b>

            <font color='#009900'>// if an edge is selected
</font>            <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>edge_selected<font face='Lucida Console'>)</font>
            <b>{</b>
                <font color='#009900'>// deselect the node if the user hits escape
</font>                <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>key <font color='#5555FF'>=</font><font color='#5555FF'>=</font> base_window::KEY_ESC<font face='Lucida Console'>)</font>
                <b>{</b>
                    parent.<font color='#BB00BB'>invalidate_rectangle</font><font face='Lucida Console'>(</font><font color='#BB00BB'>display_rect</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
                    edge_selected <font color='#5555FF'>=</font> <font color='#979000'>false</font>;
                <b>}</b>

                <font color='#009900'>// delete the node if the user hits delete 
</font>                <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>key <font color='#5555FF'>=</font><font color='#5555FF'>=</font> base_window::KEY_DELETE <font color='#5555FF'>|</font><font color='#5555FF'>|</font> key <font color='#5555FF'>=</font><font color='#5555FF'>=</font> base_window::KEY_BACKSPACE<font face='Lucida Console'>)</font>
                <b>{</b>
                    parent.<font color='#BB00BB'>invalidate_rectangle</font><font face='Lucida Console'>(</font><font color='#BB00BB'>display_rect</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
                    graph_.<font color='#BB00BB'>remove_edge</font><font face='Lucida Console'>(</font>selected_edge_parent, selected_edge_child<font face='Lucida Console'>)</font>;
                    external_graph.<font color='#BB00BB'>remove_edge</font><font face='Lucida Console'>(</font>selected_edge_parent, selected_edge_child<font face='Lucida Console'>)</font>;
                    edge_selected <font color='#5555FF'>=</font> <font color='#979000'>false</font>;

                    <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>graph_modified_handler.<font color='#BB00BB'>is_set</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>
                        <font color='#BB00BB'>graph_modified_handler</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
                <b>}</b>
            <b>}</b>
        <b>}</b>


        <font color='#0000FF'><u>void</u></font> <b><a name='on_mouse_move'></a>on_mouse_move</b> <font face='Lucida Console'>(</font>
            <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> state,
            <font color='#0000FF'><u>long</u></font> x,
            <font color='#0000FF'><u>long</u></font> y
        <font face='Lucida Console'>)</font>
        <b>{</b>
            <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>mouse_drag<font face='Lucida Console'>)</font>
            <b>{</b>
                <font color='#0000FF'>const</font> point <font color='#BB00BB'>p</font><font face='Lucida Console'>(</font><font color='#BB00BB'>nearest_point</font><font face='Lucida Console'>(</font><font color='#BB00BB'>display_rect</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>,<font color='#BB00BB'>point</font><font face='Lucida Console'>(</font>x,y<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;

                point center <font color='#5555FF'>=</font> drag_offset <font color='#5555FF'>+</font> p;
                graph_.<font color='#BB00BB'>node</font><font face='Lucida Console'>(</font>selected_node<font face='Lucida Console'>)</font>.data.p <font color='#5555FF'>=</font> <font color='#BB00BB'>gui_to_graph_space</font><font face='Lucida Console'>(</font>center<font face='Lucida Console'>)</font>;
                parent.<font color='#BB00BB'>invalidate_rectangle</font><font face='Lucida Console'>(</font><font color='#BB00BB'>display_rect</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
            <b>}</b>
            <font color='#0000FF'>else</font>
            <b>{</b>
                zoomable_region::<font color='#BB00BB'>on_mouse_move</font><font face='Lucida Console'>(</font>state,x,y<font face='Lucida Console'>)</font>;
            <b>}</b>

            <font color='#009900'>// check if the mouse isn't being dragged anymore
</font>            <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font><font face='Lucida Console'>(</font>state <font color='#5555FF'>&amp;</font> base_window::LEFT<font face='Lucida Console'>)</font> <font color='#5555FF'>=</font><font color='#5555FF'>=</font> <font color='#979000'>0</font><font face='Lucida Console'>)</font>
            <b>{</b>
                mouse_drag <font color='#5555FF'>=</font> <font color='#979000'>false</font>;
            <b>}</b>
        <b>}</b>

        <font color='#0000FF'><u>void</u></font> <b><a name='on_mouse_up'></a>on_mouse_up</b> <font face='Lucida Console'>(</font>
            <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> btn,
            <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> state,
            <font color='#0000FF'><u>long</u></font> x,
            <font color='#0000FF'><u>long</u></font> y
        <font face='Lucida Console'>)</font>
        <b>{</b>
            mouse_drag <font color='#5555FF'>=</font> <font color='#979000'>false</font>;
            zoomable_region::<font color='#BB00BB'>on_mouse_up</font><font face='Lucida Console'>(</font>btn,state,x,y<font face='Lucida Console'>)</font>;
        <b>}</b>

        <font color='#0000FF'><u>void</u></font> <b><a name='on_mouse_down'></a>on_mouse_down</b> <font face='Lucida Console'>(</font>
            <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> btn,
            <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> state,
            <font color='#0000FF'><u>long</u></font> x,
            <font color='#0000FF'><u>long</u></font> y,
            <font color='#0000FF'><u>bool</u></font> is_double_click
        <font face='Lucida Console'>)</font>
        <b>{</b>
            <font color='#0000FF'><u>bool</u></font> redraw <font color='#5555FF'>=</font> <font color='#979000'>false</font>;

            <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font><font color='#BB00BB'>display_rect</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>.<font color='#BB00BB'>contains</font><font face='Lucida Console'>(</font>x,y<font face='Lucida Console'>)</font> <font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font> 
                <font face='Lucida Console'>(</font>btn <font color='#5555FF'>=</font><font color='#5555FF'>=</font> base_window::RIGHT <font color='#5555FF'>|</font><font color='#5555FF'>|</font> btn <font color='#5555FF'>=</font><font color='#5555FF'>=</font> base_window::LEFT<font face='Lucida Console'>)</font> <font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font> 
                <font face='Lucida Console'>(</font>state <font color='#5555FF'>&amp;</font> base_window::SHIFT<font face='Lucida Console'>)</font> <font color='#5555FF'>=</font><font color='#5555FF'>=</font> <font color='#979000'>0</font> <font face='Lucida Console'>)</font>
            <b>{</b>
                <font color='#009900'>// start out saying no edge is selected
</font>                <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>edge_selected<font face='Lucida Console'>)</font>
                <b>{</b>
                    edge_selected <font color='#5555FF'>=</font> <font color='#979000'>false</font>;
                    redraw <font color='#5555FF'>=</font> <font color='#979000'>true</font>;
                <b>}</b>

                <font color='#0000FF'><u>bool</u></font> click_hit_node <font color='#5555FF'>=</font> <font color='#979000'>false</font>;
                dlib::vector<font color='#5555FF'>&lt;</font><font color='#0000FF'><u>double</u></font>,<font color='#979000'>2</font><font color='#5555FF'>&gt;</font> <font color='#BB00BB'>p</font><font face='Lucida Console'>(</font><font color='#BB00BB'>gui_to_graph_space</font><font face='Lucida Console'>(</font><font color='#BB00BB'>point</font><font face='Lucida Console'>(</font>x,y<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
                <font color='#009900'>// check if this click is on an existing node
</font>                <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font><font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> i <font color='#5555FF'>=</font> <font color='#979000'>0</font>; i <font color='#5555FF'>&lt;</font> graph_.<font color='#BB00BB'>number_of_nodes</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>i<font face='Lucida Console'>)</font>
                <b>{</b>
                    dlib::vector<font color='#5555FF'>&lt;</font><font color='#0000FF'><u>double</u></font>,<font color='#979000'>2</font><font color='#5555FF'>&gt;</font> <font color='#BB00BB'>n</font><font face='Lucida Console'>(</font>graph_.<font color='#BB00BB'>node</font><font face='Lucida Console'>(</font>i<font face='Lucida Console'>)</font>.data.p<font face='Lucida Console'>)</font>;
                    <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font><font face='Lucida Console'>(</font>p<font color='#5555FF'>-</font>n<font face='Lucida Console'>)</font>.<font color='#BB00BB'>length</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>&lt;</font> radius<font face='Lucida Console'>)</font>
                    <b>{</b>
                        click_hit_node <font color='#5555FF'>=</font> <font color='#979000'>true</font>;
                        point center <font color='#5555FF'>=</font> <font color='#BB00BB'>graph_to_gui_space</font><font face='Lucida Console'>(</font>graph_.<font color='#BB00BB'>node</font><font face='Lucida Console'>(</font>i<font face='Lucida Console'>)</font>.data.p<font face='Lucida Console'>)</font>;
                        mouse_drag <font color='#5555FF'>=</font> <font color='#979000'>true</font>;
                        drag_offset <font color='#5555FF'>=</font> center <font color='#5555FF'>-</font> <font color='#BB00BB'>point</font><font face='Lucida Console'>(</font>x,y<font face='Lucida Console'>)</font>;

                        <font color='#009900'>// only do something if the click isn't on the currently
</font>                        <font color='#009900'>// selected node
</font>                        <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>selected_node <font color='#5555FF'>!</font><font color='#5555FF'>=</font> i<font face='Lucida Console'>)</font>
                        <b>{</b>
                            <font color='#009900'>// send out the deselected event if appropriate
</font>                            <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>selected_node <font color='#5555FF'>!</font><font color='#5555FF'>=</font> graph_.<font color='#BB00BB'>number_of_nodes</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font> node_deselected_handler.<font color='#BB00BB'>is_set</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>
                                <font color='#BB00BB'>node_deselected_handler</font><font face='Lucida Console'>(</font>selected_node<font face='Lucida Console'>)</font>;

                            selected_node <font color='#5555FF'>=</font> i;
                            redraw <font color='#5555FF'>=</font> <font color='#979000'>true</font>;
                            <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>node_selected_handler.<font color='#BB00BB'>is_set</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>
                                <font color='#BB00BB'>node_selected_handler</font><font face='Lucida Console'>(</font>selected_node<font face='Lucida Console'>)</font>;
                        <b>}</b>
                        <font color='#0000FF'>break</font>;
                    <b>}</b>
                <b>}</b>

                <font color='#009900'>// if the click didn't hit any node then make sure nothing is selected
</font>                <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>click_hit_node <font color='#5555FF'>=</font><font color='#5555FF'>=</font> <font color='#979000'>false</font> <font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font> selected_node <font color='#5555FF'>!</font><font color='#5555FF'>=</font> graph_.<font color='#BB00BB'>number_of_nodes</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>
                <b>{</b>
                    <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>node_deselected_handler.<font color='#BB00BB'>is_set</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>
                        <font color='#BB00BB'>node_deselected_handler</font><font face='Lucida Console'>(</font>selected_node<font face='Lucida Console'>)</font>;
                    selected_node <font color='#5555FF'>=</font> graph_.<font color='#BB00BB'>number_of_nodes</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
                    redraw <font color='#5555FF'>=</font> <font color='#979000'>true</font>;
                <b>}</b>


                <font color='#009900'>// check if this click is on an edge if we didn't click on a node
</font>                <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>click_hit_node <font color='#5555FF'>=</font><font color='#5555FF'>=</font> <font color='#979000'>false</font><font face='Lucida Console'>)</font>
                <b>{</b>
                    <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font><font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> n <font color='#5555FF'>=</font> <font color='#979000'>0</font>; n <font color='#5555FF'>&lt;</font> graph_.<font color='#BB00BB'>number_of_nodes</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font> edge_selected <font color='#5555FF'>=</font><font color='#5555FF'>=</font> <font color='#979000'>false</font>; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>n<font face='Lucida Console'>)</font>
                    <b>{</b>
                        <font color='#0000FF'>const</font> dlib::vector<font color='#5555FF'>&lt;</font><font color='#0000FF'><u>double</u></font>,<font color='#979000'>2</font><font color='#5555FF'>&gt;</font> <font color='#BB00BB'>parent_center</font><font face='Lucida Console'>(</font><font color='#BB00BB'>graph_to_gui_space</font><font face='Lucida Console'>(</font>graph_.<font color='#BB00BB'>node</font><font face='Lucida Console'>(</font>n<font face='Lucida Console'>)</font>.data.p<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
                        <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font><font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> e <font color='#5555FF'>=</font> <font color='#979000'>0</font>; e <font color='#5555FF'>&lt;</font> graph_.<font color='#BB00BB'>node</font><font face='Lucida Console'>(</font>n<font face='Lucida Console'>)</font>.<font color='#BB00BB'>number_of_children</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font> edge_selected <font color='#5555FF'>=</font><font color='#5555FF'>=</font> <font color='#979000'>false</font>; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>e<font face='Lucida Console'>)</font>
                        <b>{</b>
                            <font color='#0000FF'>const</font> dlib::vector<font color='#5555FF'>&lt;</font><font color='#0000FF'><u>double</u></font>,<font color='#979000'>2</font><font color='#5555FF'>&gt;</font> <font color='#BB00BB'>child_center</font><font face='Lucida Console'>(</font><font color='#BB00BB'>graph_to_gui_space</font><font face='Lucida Console'>(</font>graph_.<font color='#BB00BB'>node</font><font face='Lucida Console'>(</font>n<font face='Lucida Console'>)</font>.<font color='#BB00BB'>child</font><font face='Lucida Console'>(</font>e<font face='Lucida Console'>)</font>.data.p<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;

                            rectangle area;
                            area <font color='#5555FF'>+</font><font color='#5555FF'>=</font> parent_center;
                            area <font color='#5555FF'>+</font><font color='#5555FF'>=</font> child_center;
                            <font color='#009900'>// if the point(x,y) is between the two nodes then lets consider it further
</font>                            <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>area.<font color='#BB00BB'>contains</font><font face='Lucida Console'>(</font><font color='#BB00BB'>point</font><font face='Lucida Console'>(</font>x,y<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>
                            <b>{</b>
                                p <font color='#5555FF'>=</font> <font color='#BB00BB'>point</font><font face='Lucida Console'>(</font>x,y<font face='Lucida Console'>)</font>;
                                <font color='#0000FF'>const</font> dlib::vector<font color='#5555FF'>&lt;</font><font color='#0000FF'><u>double</u></font><font color='#5555FF'>&gt;</font> <font color='#BB00BB'>z</font><font face='Lucida Console'>(</font><font color='#979000'>0</font>,<font color='#979000'>0</font>,<font color='#979000'>1</font><font face='Lucida Console'>)</font>;
                                <font color='#009900'>// find the distance from the line between the two nodes
</font>                                <font color='#0000FF'>const</font> dlib::vector<font color='#5555FF'>&lt;</font><font color='#0000FF'><u>double</u></font>,<font color='#979000'>2</font><font color='#5555FF'>&gt;</font> <font color='#BB00BB'>perpendicular</font><font face='Lucida Console'>(</font>z.<font color='#BB00BB'>cross</font><font face='Lucida Console'>(</font>parent_center<font color='#5555FF'>-</font>child_center<font face='Lucida Console'>)</font>.<font color='#BB00BB'>normalize</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
                                <font color='#0000FF'><u>double</u></font> distance <font color='#5555FF'>=</font> std::<font color='#BB00BB'>abs</font><font face='Lucida Console'>(</font><font face='Lucida Console'>(</font>child_center<font color='#5555FF'>-</font>p<font face='Lucida Console'>)</font>.<font color='#BB00BB'>dot</font><font face='Lucida Console'>(</font>perpendicular<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
                                <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>distance <font color='#5555FF'>&lt;</font> <font color='#979000'>8</font><font face='Lucida Console'>)</font>
                                <b>{</b>
                                    edge_selected <font color='#5555FF'>=</font> <font color='#979000'>true</font>;
                                    selected_edge_parent <font color='#5555FF'>=</font> n;
                                    selected_edge_child <font color='#5555FF'>=</font> graph_.<font color='#BB00BB'>node</font><font face='Lucida Console'>(</font>n<font face='Lucida Console'>)</font>.<font color='#BB00BB'>child</font><font face='Lucida Console'>(</font>e<font face='Lucida Console'>)</font>.<font color='#BB00BB'>index</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
                                    redraw <font color='#5555FF'>=</font> <font color='#979000'>true</font>;
                                <b>}</b>
                            <b>}</b>
                        <b>}</b>
                    <b>}</b>
                <b>}</b>


                <font color='#009900'>// if the click didn't land on any node then add a new one if this was
</font>                <font color='#009900'>// a right mouse button click
</font>                <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>click_hit_node <font color='#5555FF'>=</font><font color='#5555FF'>=</font> <font color='#979000'>false</font> <font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font> btn <font color='#5555FF'>=</font><font color='#5555FF'>=</font> base_window::RIGHT<font face='Lucida Console'>)</font>
                <b>{</b>
                    <font color='#0000FF'>const</font> <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> n <font color='#5555FF'>=</font> graph_.<font color='#BB00BB'>add_node</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
                    external_graph.<font color='#BB00BB'>add_node</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;

                    graph_.<font color='#BB00BB'>node</font><font face='Lucida Console'>(</font>n<font face='Lucida Console'>)</font>.data.p <font color='#5555FF'>=</font> <font color='#BB00BB'>gui_to_graph_space</font><font face='Lucida Console'>(</font><font color='#BB00BB'>point</font><font face='Lucida Console'>(</font>x,y<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;

                    redraw <font color='#5555FF'>=</font> <font color='#979000'>true</font>;
                    selected_node <font color='#5555FF'>=</font> n;
                    mouse_drag <font color='#5555FF'>=</font> <font color='#979000'>false</font>;
                    <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>graph_modified_handler.<font color='#BB00BB'>is_set</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>
                        <font color='#BB00BB'>graph_modified_handler</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;

                    <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>node_selected_handler.<font color='#BB00BB'>is_set</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>
                        <font color='#BB00BB'>node_selected_handler</font><font face='Lucida Console'>(</font>selected_node<font face='Lucida Console'>)</font>;

                <b>}</b>
                <font color='#0000FF'>else</font> <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>selected_node <font color='#5555FF'>=</font><font color='#5555FF'>=</font> graph_.<font color='#BB00BB'>number_of_nodes</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>
                <b>{</b>
                    <font color='#009900'>// in this case the click landed in the white area between nodes
</font>                    zoomable_region::<font color='#BB00BB'>on_mouse_down</font><font face='Lucida Console'>(</font> btn, state, x, y, is_double_click<font face='Lucida Console'>)</font>;
                <b>}</b>
            <b>}</b>

            <font color='#009900'>// If the user is shift clicking with the mouse then see if we
</font>            <font color='#009900'>// should add a new edge.
</font>            <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font><font color='#BB00BB'>display_rect</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>.<font color='#BB00BB'>contains</font><font face='Lucida Console'>(</font>x,y<font face='Lucida Console'>)</font> <font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font> 
                btn <font color='#5555FF'>=</font><font color='#5555FF'>=</font> base_window::LEFT <font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font> 
                <font face='Lucida Console'>(</font>state <font color='#5555FF'>&amp;</font> base_window::SHIFT<font face='Lucida Console'>)</font> <font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font> 
                selected_node <font color='#5555FF'>!</font><font color='#5555FF'>=</font> graph_.<font color='#BB00BB'>number_of_nodes</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font face='Lucida Console'>)</font>
            <b>{</b>
                dlib::vector<font color='#5555FF'>&lt;</font><font color='#0000FF'><u>double</u></font>,<font color='#979000'>2</font><font color='#5555FF'>&gt;</font> <font color='#BB00BB'>p</font><font face='Lucida Console'>(</font><font color='#BB00BB'>gui_to_graph_space</font><font face='Lucida Console'>(</font><font color='#BB00BB'>point</font><font face='Lucida Console'>(</font>x,y<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
                <font color='#009900'>// check if this click is on an existing node
</font>                <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font><font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> i <font color='#5555FF'>=</font> <font color='#979000'>0</font>; i <font color='#5555FF'>&lt;</font> graph_.<font color='#BB00BB'>number_of_nodes</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>i<font face='Lucida Console'>)</font>
                <b>{</b>
                    dlib::vector<font color='#5555FF'>&lt;</font><font color='#0000FF'><u>double</u></font>,<font color='#979000'>2</font><font color='#5555FF'>&gt;</font> <font color='#BB00BB'>n</font><font face='Lucida Console'>(</font>graph_.<font color='#BB00BB'>node</font><font face='Lucida Console'>(</font>i<font face='Lucida Console'>)</font>.data.p<font face='Lucida Console'>)</font>;
                    <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font><font face='Lucida Console'>(</font>p<font color='#5555FF'>-</font>n<font face='Lucida Console'>)</font>.<font color='#BB00BB'>length</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>&lt;</font> radius<font face='Lucida Console'>)</font>
                    <b>{</b>
                        <font color='#009900'>// add the edge if it doesn't already exist and isn't an edge back to 
</font>                        <font color='#009900'>// the same node
</font>                        <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>graph_.<font color='#BB00BB'>has_edge</font><font face='Lucida Console'>(</font>selected_node,i<font face='Lucida Console'>)</font> <font color='#5555FF'>=</font><font color='#5555FF'>=</font> <font color='#979000'>false</font> <font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font> selected_node <font color='#5555FF'>!</font><font color='#5555FF'>=</font> i <font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font>
                            graph_.<font color='#BB00BB'>has_edge</font><font face='Lucida Console'>(</font>i, selected_node<font face='Lucida Console'>)</font> <font color='#5555FF'>=</font><font color='#5555FF'>=</font> <font color='#979000'>false</font><font face='Lucida Console'>)</font>
                        <b>{</b>
                            graph_.<font color='#BB00BB'>add_edge</font><font face='Lucida Console'>(</font>selected_node,i<font face='Lucida Console'>)</font>;
                            external_graph.<font color='#BB00BB'>add_edge</font><font face='Lucida Console'>(</font>selected_node,i<font face='Lucida Console'>)</font>;
                            redraw <font color='#5555FF'>=</font> <font color='#979000'>true</font>;

                            <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>graph_modified_handler.<font color='#BB00BB'>is_set</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>
                                <font color='#BB00BB'>graph_modified_handler</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
                        <b>}</b>
                        <font color='#0000FF'>break</font>;
                    <b>}</b>
                <b>}</b>
            <b>}</b>


            <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>redraw<font face='Lucida Console'>)</font>
                parent.<font color='#BB00BB'>invalidate_rectangle</font><font face='Lucida Console'>(</font><font color='#BB00BB'>display_rect</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;


            <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font><font color='#BB00BB'>display_rect</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>.<font color='#BB00BB'>contains</font><font face='Lucida Console'>(</font>x,y<font face='Lucida Console'>)</font> <font color='#5555FF'>=</font><font color='#5555FF'>=</font> <font color='#979000'>false</font><font face='Lucida Console'>)</font>
                last_mouse_click_in_display <font color='#5555FF'>=</font> <font color='#979000'>false</font>;
            <font color='#0000FF'>else</font>
                last_mouse_click_in_display <font color='#5555FF'>=</font> <font color='#979000'>true</font>;
        <b>}</b>

        <font color='#0000FF'><u>void</u></font> <b><a name='draw'></a>draw</b> <font face='Lucida Console'>(</font>
            <font color='#0000FF'>const</font> canvas<font color='#5555FF'>&amp;</font> c
        <font face='Lucida Console'>)</font> <font color='#0000FF'>const</font>
        <b>{</b>
            zoomable_region::<font color='#BB00BB'>draw</font><font face='Lucida Console'>(</font>c<font face='Lucida Console'>)</font>;

            rectangle area <font color='#5555FF'>=</font> c.<font color='#BB00BB'>intersect</font><font face='Lucida Console'>(</font><font color='#BB00BB'>display_rect</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
            <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>area.<font color='#BB00BB'>is_empty</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>=</font><font color='#5555FF'>=</font> <font color='#979000'>true</font><font face='Lucida Console'>)</font>
                <font color='#0000FF'>return</font>;


            <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>enabled<font face='Lucida Console'>)</font>
                <font color='#BB00BB'>fill_rect</font><font face='Lucida Console'>(</font>c,<font color='#BB00BB'>display_rect</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>,<font color='#979000'>255</font><font face='Lucida Console'>)</font>;
            <font color='#0000FF'>else</font>
                <font color='#BB00BB'>fill_rect</font><font face='Lucida Console'>(</font>c,<font color='#BB00BB'>display_rect</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>,<font color='#979000'>128</font><font face='Lucida Console'>)</font>;


            <font color='#0000FF'>const</font> <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> rad <font color='#5555FF'>=</font> <font color='#0000FF'>static_cast</font><font color='#5555FF'>&lt;</font><font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font><font color='#5555FF'>&gt;</font><font face='Lucida Console'>(</font>radius<font color='#5555FF'>*</font><font color='#BB00BB'>zoom_scale</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
            point center;


            <font color='#009900'>// first draw all the edges
</font>            <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font><font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> i <font color='#5555FF'>=</font> <font color='#979000'>0</font>; i <font color='#5555FF'>&lt;</font> graph_.<font color='#BB00BB'>number_of_nodes</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>i<font face='Lucida Console'>)</font>
            <b>{</b>
                center <font color='#5555FF'>=</font> <font color='#BB00BB'>graph_to_gui_space</font><font face='Lucida Console'>(</font>graph_.<font color='#BB00BB'>node</font><font face='Lucida Console'>(</font>i<font face='Lucida Console'>)</font>.data.p<font face='Lucida Console'>)</font>;
                <font color='#0000FF'>const</font> rectangle <font color='#BB00BB'>circle_area</font><font face='Lucida Console'>(</font><font color='#BB00BB'>centered_rect</font><font face='Lucida Console'>(</font>center,<font color='#979000'>2</font><font color='#5555FF'>*</font><font face='Lucida Console'>(</font>rad<font color='#5555FF'>+</font><font color='#979000'>8</font><font face='Lucida Console'>)</font>,<font color='#979000'>2</font><font color='#5555FF'>*</font><font face='Lucida Console'>(</font>rad<font color='#5555FF'>+</font><font color='#979000'>8</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;

                <font color='#009900'>// draw lines to all this node's parents 
</font>                <font color='#0000FF'>const</font> dlib::vector<font color='#5555FF'>&lt;</font><font color='#0000FF'><u>double</u></font><font color='#5555FF'>&gt;</font> <font color='#BB00BB'>z</font><font face='Lucida Console'>(</font><font color='#979000'>0</font>,<font color='#979000'>0</font>,<font color='#979000'>1</font><font face='Lucida Console'>)</font>;
                <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font><font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> j <font color='#5555FF'>=</font> <font color='#979000'>0</font>; j <font color='#5555FF'>&lt;</font> graph_.<font color='#BB00BB'>node</font><font face='Lucida Console'>(</font>i<font face='Lucida Console'>)</font>.<font color='#BB00BB'>number_of_parents</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>j<font face='Lucida Console'>)</font>
                <b>{</b>
                    point <font color='#BB00BB'>p</font><font face='Lucida Console'>(</font><font color='#BB00BB'>graph_to_gui_space</font><font face='Lucida Console'>(</font>graph_.<font color='#BB00BB'>node</font><font face='Lucida Console'>(</font>i<font face='Lucida Console'>)</font>.<font color='#BB00BB'>parent</font><font face='Lucida Console'>(</font>j<font face='Lucida Console'>)</font>.data.p<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;

                    rgb_pixel <font color='#BB00BB'>color</font><font face='Lucida Console'>(</font><font color='#979000'>0</font>,<font color='#979000'>0</font>,<font color='#979000'>0</font><font face='Lucida Console'>)</font>;
                    <font color='#009900'>// if this is the selected edge then draw it with red instead of black
</font>                    <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>edge_selected <font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font> selected_edge_child <font color='#5555FF'>=</font><font color='#5555FF'>=</font> i <font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font> selected_edge_parent <font color='#5555FF'>=</font><font color='#5555FF'>=</font> graph_.<font color='#BB00BB'>node</font><font face='Lucida Console'>(</font>i<font face='Lucida Console'>)</font>.<font color='#BB00BB'>parent</font><font face='Lucida Console'>(</font>j<font face='Lucida Console'>)</font>.<font color='#BB00BB'>index</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>
                    <b>{</b>
                        color.red <font color='#5555FF'>=</font> <font color='#979000'>255</font>;
                        <font color='#009900'>// we need to be careful when drawing this line to not draw it over the node dots since it 
</font>                        <font color='#009900'>// has a different color from them and would look weird
</font>                        dlib::vector<font color='#5555FF'>&lt;</font><font color='#0000FF'><u>double</u></font>,<font color='#979000'>2</font><font color='#5555FF'>&gt;</font> <font color='#BB00BB'>v</font><font face='Lucida Console'>(</font>p<font color='#5555FF'>-</font>center<font face='Lucida Console'>)</font>;
                        v <font color='#5555FF'>=</font> v.<font color='#BB00BB'>normalize</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>*</font>rad;
                        <font color='#BB00BB'>draw_line</font><font face='Lucida Console'>(</font>c,center<font color='#5555FF'>+</font>v,p<font color='#5555FF'>-</font>v ,color, area<font face='Lucida Console'>)</font>;
                    <b>}</b>
                    <font color='#0000FF'>else</font>
                    <b>{</b>
                        <font color='#BB00BB'>draw_line</font><font face='Lucida Console'>(</font>c,center,p ,color, area<font face='Lucida Console'>)</font>;
                    <b>}</b>


                    <font color='#009900'>// draw the triangle pointing to this node
</font>                    <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>area.<font color='#BB00BB'>intersect</font><font face='Lucida Console'>(</font>circle_area<font face='Lucida Console'>)</font>.<font color='#BB00BB'>is_empty</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>=</font><font color='#5555FF'>=</font> <font color='#979000'>false</font><font face='Lucida Console'>)</font>
                    <b>{</b>
                        dlib::vector<font color='#5555FF'>&lt;</font><font color='#0000FF'><u>double</u></font>,<font color='#979000'>2</font><font color='#5555FF'>&gt;</font> <font color='#BB00BB'>v</font><font face='Lucida Console'>(</font>p<font color='#5555FF'>-</font>center<font face='Lucida Console'>)</font>;
                        v <font color='#5555FF'>=</font> v.<font color='#BB00BB'>normalize</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;

                        dlib::vector<font color='#5555FF'>&lt;</font><font color='#0000FF'><u>double</u></font>,<font color='#979000'>2</font><font color='#5555FF'>&gt;</font> cross <font color='#5555FF'>=</font> z.<font color='#BB00BB'>cross</font><font face='Lucida Console'>(</font>v<font face='Lucida Console'>)</font>.<font color='#BB00BB'>normalize</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
                        dlib::vector<font color='#5555FF'>&lt;</font><font color='#0000FF'><u>double</u></font>,<font color='#979000'>2</font><font color='#5555FF'>&gt;</font> <font color='#BB00BB'>r</font><font face='Lucida Console'>(</font>center <font color='#5555FF'>+</font> v<font color='#5555FF'>*</font>rad<font face='Lucida Console'>)</font>;
                        <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font><font color='#0000FF'><u>double</u></font> i <font color='#5555FF'>=</font> <font color='#979000'>0</font>; i <font color='#5555FF'>&lt;</font> <font color='#979000'>8</font><font color='#5555FF'>*</font><font color='#BB00BB'>zoom_scale</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>; i <font color='#5555FF'>+</font><font color='#5555FF'>=</font> <font color='#979000'>0.1</font><font face='Lucida Console'>)</font>
                            <font color='#BB00BB'>draw_line</font><font face='Lucida Console'>(</font>c,<font face='Lucida Console'>(</font>r<font color='#5555FF'>+</font>v<font color='#5555FF'>*</font>i<font face='Lucida Console'>)</font><font color='#5555FF'>+</font>cross<font color='#5555FF'>*</font>i, <font face='Lucida Console'>(</font>r<font color='#5555FF'>+</font>v<font color='#5555FF'>*</font>i<font face='Lucida Console'>)</font><font color='#5555FF'>-</font>cross<font color='#5555FF'>*</font>i,color,area<font face='Lucida Console'>)</font>;
                    <b>}</b>
                <b>}</b>
            <b>}</b>


            <font color='#009900'>// now draw all the node dots
</font>            <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font><font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> i <font color='#5555FF'>=</font> <font color='#979000'>0</font>; i <font color='#5555FF'>&lt;</font> graph_.<font color='#BB00BB'>number_of_nodes</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>i<font face='Lucida Console'>)</font>
            <b>{</b>
                center <font color='#5555FF'>=</font> <font color='#BB00BB'>graph_to_gui_space</font><font face='Lucida Console'>(</font>graph_.<font color='#BB00BB'>node</font><font face='Lucida Console'>(</font>i<font face='Lucida Console'>)</font>.data.p<font face='Lucida Console'>)</font>;
                <font color='#0000FF'>const</font> rectangle <font color='#BB00BB'>circle_area</font><font face='Lucida Console'>(</font><font color='#BB00BB'>centered_rect</font><font face='Lucida Console'>(</font>center,<font color='#979000'>2</font><font color='#5555FF'>*</font><font face='Lucida Console'>(</font>rad<font color='#5555FF'>+</font><font color='#979000'>8</font><font face='Lucida Console'>)</font>,<font color='#979000'>2</font><font color='#5555FF'>*</font><font face='Lucida Console'>(</font>rad<font color='#5555FF'>+</font><font color='#979000'>8</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;

                <font color='#009900'>// draw the actual dot for this node
</font>                <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>area.<font color='#BB00BB'>intersect</font><font face='Lucida Console'>(</font>circle_area<font face='Lucida Console'>)</font>.<font color='#BB00BB'>is_empty</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>=</font><font color='#5555FF'>=</font><font color='#979000'>false</font><font face='Lucida Console'>)</font>
                <b>{</b>
                    rgb_alpha_pixel color;
                    <font color='#BB00BB'>assign_pixel</font><font face='Lucida Console'>(</font>color, graph_.<font color='#BB00BB'>node</font><font face='Lucida Console'>(</font>i<font face='Lucida Console'>)</font>.data.color<font face='Lucida Console'>)</font>;
                    <font color='#009900'>// this node is in area so lets draw it and all of it's edges as well
</font>                    <font color='#BB00BB'>draw_solid_circle</font><font face='Lucida Console'>(</font>c,center,rad<font color='#5555FF'>-</font><font color='#979000'>3</font>,color,area<font face='Lucida Console'>)</font>;
                    color.alpha <font color='#5555FF'>=</font> <font color='#979000'>240</font>;
                    <font color='#BB00BB'>draw_circle</font><font face='Lucida Console'>(</font>c,center,rad<font color='#5555FF'>-</font><font color='#979000'>3</font>,color,area<font face='Lucida Console'>)</font>;
                    color.alpha <font color='#5555FF'>=</font> <font color='#979000'>200</font>;
                    <font color='#BB00BB'>draw_circle</font><font face='Lucida Console'>(</font>c,center,rad<font color='#5555FF'>-</font><font color='#979000'>2.5</font>,color,area<font face='Lucida Console'>)</font>;
                    color.alpha <font color='#5555FF'>=</font> <font color='#979000'>160</font>;
                    <font color='#BB00BB'>draw_circle</font><font face='Lucida Console'>(</font>c,center,rad<font color='#5555FF'>-</font><font color='#979000'>2.0</font>,color,area<font face='Lucida Console'>)</font>;
                    color.alpha <font color='#5555FF'>=</font> <font color='#979000'>120</font>;
                    <font color='#BB00BB'>draw_circle</font><font face='Lucida Console'>(</font>c,center,rad<font color='#5555FF'>-</font><font color='#979000'>1.5</font>,color,area<font face='Lucida Console'>)</font>;
                    color.alpha <font color='#5555FF'>=</font> <font color='#979000'>80</font>;
                    <font color='#BB00BB'>draw_circle</font><font face='Lucida Console'>(</font>c,center,rad<font color='#5555FF'>-</font><font color='#979000'>1.0</font>,color,area<font face='Lucida Console'>)</font>;
                    color.alpha <font color='#5555FF'>=</font> <font color='#979000'>40</font>;
                    <font color='#BB00BB'>draw_circle</font><font face='Lucida Console'>(</font>c,center,rad<font color='#5555FF'>-</font><font color='#979000'>0.5</font>,color,area<font face='Lucida Console'>)</font>;

                <b>}</b>


                <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>i <font color='#5555FF'>=</font><font color='#5555FF'>=</font> selected_node<font face='Lucida Console'>)</font>
                    <font color='#BB00BB'>draw_circle</font><font face='Lucida Console'>(</font>c,center,rad<font color='#5555FF'>+</font><font color='#979000'>5</font>,<font color='#BB00BB'>rgb_pixel</font><font face='Lucida Console'>(</font><font color='#979000'>0</font>,<font color='#979000'>0</font>,<font color='#979000'>255</font><font face='Lucida Console'>)</font>,area<font face='Lucida Console'>)</font>;
            <b>}</b>


            <font color='#009900'>// now draw all the strings last
</font>            <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font><font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> i <font color='#5555FF'>=</font> <font color='#979000'>0</font>; i <font color='#5555FF'>&lt;</font> graph_.<font color='#BB00BB'>number_of_nodes</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>i<font face='Lucida Console'>)</font>
            <b>{</b>
                center <font color='#5555FF'>=</font> <font color='#BB00BB'>graph_to_gui_space</font><font face='Lucida Console'>(</font>graph_.<font color='#BB00BB'>node</font><font face='Lucida Console'>(</font>i<font face='Lucida Console'>)</font>.data.p<font face='Lucida Console'>)</font>;
                rectangle <font color='#BB00BB'>circle_area</font><font face='Lucida Console'>(</font><font color='#BB00BB'>centered_rect</font><font face='Lucida Console'>(</font>center,<font color='#979000'>2</font><font color='#5555FF'>*</font>rad<font color='#5555FF'>+</font><font color='#979000'>3</font>,<font color='#979000'>2</font><font color='#5555FF'>*</font>rad<font color='#5555FF'>+</font><font color='#979000'>3</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
                <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>area.<font color='#BB00BB'>intersect</font><font face='Lucida Console'>(</font>circle_area<font face='Lucida Console'>)</font>.<font color='#BB00BB'>is_empty</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>=</font><font color='#5555FF'>=</font><font color='#979000'>false</font><font face='Lucida Console'>)</font>
                <b>{</b>
                    rgb_pixel color <font color='#5555FF'>=</font> graph_.<font color='#BB00BB'>node</font><font face='Lucida Console'>(</font>i<font face='Lucida Console'>)</font>.data.color;
                    <font color='#009900'>// invert this color
</font>                    color.red <font color='#5555FF'>=</font> <font color='#979000'>255</font><font color='#5555FF'>-</font>color.red;
                    color.green <font color='#5555FF'>=</font> <font color='#979000'>255</font><font color='#5555FF'>-</font>color.green;
                    color.blue <font color='#5555FF'>=</font> <font color='#979000'>255</font><font color='#5555FF'>-</font>color.blue;
                    sout <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> i;
                    <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> width, height;
                    mfont<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font><font color='#BB00BB'>compute_size</font><font face='Lucida Console'>(</font>sout.<font color='#BB00BB'>str</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>,width,height<font face='Lucida Console'>)</font>;
                    rectangle <font color='#BB00BB'>str_rect</font><font face='Lucida Console'>(</font><font color='#BB00BB'>centered_rect</font><font face='Lucida Console'>(</font>center, width,height<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
                    <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>circle_area.<font color='#BB00BB'>contains</font><font face='Lucida Console'>(</font>str_rect<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>
                    <b>{</b>
                        mfont<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font><font color='#BB00BB'>draw_string</font><font face='Lucida Console'>(</font>c,str_rect,sout.<font color='#BB00BB'>str</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>,color,<font color='#979000'>0</font>,std::string::npos,area<font face='Lucida Console'>)</font>;

                        <font color='#009900'>// draw the label for this node if it isn't empty
</font>                        <font color='#0000FF'>if</font><font face='Lucida Console'>(</font>graph_.<font color='#BB00BB'>node</font><font face='Lucida Console'>(</font>i<font face='Lucida Console'>)</font>.data.name.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>&gt;</font> <font color='#979000'>0</font><font face='Lucida Console'>)</font>
                        <b>{</b>
                            rectangle <font color='#BB00BB'>str_rect</font><font face='Lucida Console'>(</font>graph_.<font color='#BB00BB'>node</font><font face='Lucida Console'>(</font>i<font face='Lucida Console'>)</font>.data.str_rect<font face='Lucida Console'>)</font>;
                            str_rect <font color='#5555FF'>=</font> <font color='#BB00BB'>centered_rect</font><font face='Lucida Console'>(</font>center.<font color='#BB00BB'>x</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>, center.<font color='#BB00BB'>y</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>-</font>rad<font color='#5555FF'>-</font>mfont<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font><font color='#BB00BB'>height</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>,  str_rect.<font color='#BB00BB'>width</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>, str_rect.<font color='#BB00BB'>height</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
                            mfont<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font><font color='#BB00BB'>draw_string</font><font face='Lucida Console'>(</font>c,str_rect,graph_.<font color='#BB00BB'>node</font><font face='Lucida Console'>(</font>i<font face='Lucida Console'>)</font>.data.name,<font color='#979000'>0</font>,<font color='#979000'>0</font>,std::string::npos,area<font face='Lucida Console'>)</font>;
                        <b>}</b>
                    <b>}</b>
                    sout.<font color='#BB00BB'>str</font><font face='Lucida Console'>(</font>"<font color='#CC0000'></font>"<font face='Lucida Console'>)</font>;
                <b>}</b>
            <b>}</b>
        <b>}</b>

    <font color='#0000FF'>private</font>:

        <font color='#0000FF'>struct</font> <b><a name='data'></a>data</b>
        <b>{</b>
            <b><a name='data'></a>data</b><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> : color<font face='Lucida Console'>(</font><font color='#979000'>0</font>,<font color='#979000'>0</font>,<font color='#979000'>0</font><font face='Lucida Console'>)</font> <b>{</b><b>}</b>
            vector<font color='#5555FF'>&lt;</font><font color='#0000FF'><u>double</u></font><font color='#5555FF'>&gt;</font> p;
            dlib::ustring name;
            rectangle str_rect;
            rgb_pixel color;
        <b>}</b>;

        <font color='#0000FF'>friend</font> <font color='#0000FF'><u>void</u></font> <b><a name='serialize'></a>serialize</b><font face='Lucida Console'>(</font><font color='#0000FF'>const</font> data<font color='#5555FF'>&amp;</font> item, std::ostream<font color='#5555FF'>&amp;</font> out<font face='Lucida Console'>)</font>
        <b>{</b>
            <font color='#BB00BB'>serialize</font><font face='Lucida Console'>(</font>item.p, out<font face='Lucida Console'>)</font>;
            <font color='#BB00BB'>serialize</font><font face='Lucida Console'>(</font>item.name, out<font face='Lucida Console'>)</font>;
            <font color='#BB00BB'>serialize</font><font face='Lucida Console'>(</font>item.str_rect, out<font face='Lucida Console'>)</font>;
            <font color='#BB00BB'>serialize</font><font face='Lucida Console'>(</font>item.color, out<font face='Lucida Console'>)</font>;
        <b>}</b>

        <font color='#0000FF'>friend</font> <font color='#0000FF'><u>void</u></font> <b><a name='deserialize'></a>deserialize</b><font face='Lucida Console'>(</font>data<font color='#5555FF'>&amp;</font> item, std::istream<font color='#5555FF'>&amp;</font> in<font face='Lucida Console'>)</font>
        <b>{</b>
            <font color='#BB00BB'>deserialize</font><font face='Lucida Console'>(</font>item.p, in<font face='Lucida Console'>)</font>;
            <font color='#BB00BB'>deserialize</font><font face='Lucida Console'>(</font>item.name, in<font face='Lucida Console'>)</font>;
            <font color='#BB00BB'>deserialize</font><font face='Lucida Console'>(</font>item.str_rect, in<font face='Lucida Console'>)</font>;
            <font color='#BB00BB'>deserialize</font><font face='Lucida Console'>(</font>item.color, in<font face='Lucida Console'>)</font>;
        <b>}</b>

        <font color='#0000FF'>mutable</font> std::ostringstream sout;

        <font color='#0000FF'>const</font> <font color='#0000FF'><u>double</u></font> radius;
        <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> selected_node;
        <font color='#0000FF'><u>bool</u></font> mouse_drag; <font color='#009900'>// true if the user is dragging a node
</font>        point drag_offset; 

        <font color='#0000FF'><u>bool</u></font> edge_selected;
        <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> selected_edge_parent;
        <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> selected_edge_child;

        any_function<font color='#5555FF'>&lt;</font><font color='#0000FF'><u>void</u></font><font face='Lucida Console'>(</font><font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font><font face='Lucida Console'>)</font><font color='#5555FF'>&gt;</font> node_selected_handler;
        any_function<font color='#5555FF'>&lt;</font><font color='#0000FF'><u>void</u></font><font face='Lucida Console'>(</font><font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font><font face='Lucida Console'>)</font><font color='#5555FF'>&gt;</font> node_deselected_handler;
        any_function<font color='#5555FF'>&lt;</font><font color='#0000FF'><u>void</u></font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>&gt;</font> node_deleted_handler;
        any_function<font color='#5555FF'>&lt;</font><font color='#0000FF'><u>void</u></font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>&gt;</font> graph_modified_handler;

        graph_type external_graph;
        <font color='#009900'>// rebind the graph_ type to make us a graph_ of data structs
</font>        <font color='#0000FF'>typename</font> graph_type::<font color='#0000FF'>template</font> rebind<font color='#5555FF'>&lt;</font>data,<font color='#0000FF'><u>char</u></font>, <font color='#0000FF'>typename</font> graph_type::mem_manager_type<font color='#5555FF'>&gt;</font>::other graph_;

        <font color='#0000FF'><u>bool</u></font> last_mouse_click_in_display;
    <b>}</b>;

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font><font color='#009900'>// ----------------------------------------------------------------------------------------
</font>    <font color='#009900'>// class text_grid
</font><font color='#009900'>// ----------------------------------------------------------------------------------------
</font><font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'>class</font> <b><a name='text_grid'></a>text_grid</b> : <font color='#0000FF'>public</font> scrollable_region 
    <b>{</b>
        <font color='#009900'>/*!
            INITIAL VALUE
                - has_focus == false
                - vertical_scroll_increment() == 10
                - horizontal_scroll_increment() == 10
                - border_color_ == rgb_pixel(128,128,128)

            CONVENTION
                - grid.nr() == row_height.size()
                - grid.nc() == col_width.size()
                - border_color() == border_color_
                - text(r,c) == grid[r][c].text
                - text_color(r,c) == grid[r][c].text_color
                - background_color(r,c) == grid[r][c].bg_color

                - if (the user has clicked on this widget and caused one of the
                    boxes to have input focus) then
                    - has_focus == true
                    - grid[active_row][active_col] == the active text box
                    - cursor_pos == the position of the cursor in the above box
                    - if (the cursor should be displayed) then
                        - show_cursor == true
                    - else
                        - show_cursor == false
                - else
                    - has_focus == false
        !*/</font>

    <font color='#0000FF'>public</font>:
        <b><a name='text_grid'></a>text_grid</b> <font face='Lucida Console'>(</font>
            drawable_window<font color='#5555FF'>&amp;</font> w
        <font face='Lucida Console'>)</font>; 

        ~<b><a name='text_grid'></a>text_grid</b> <font face='Lucida Console'>(</font>
        <font face='Lucida Console'>)</font>;

        <font color='#0000FF'><u>void</u></font> <b><a name='set_grid_size'></a>set_grid_size</b> <font face='Lucida Console'>(</font>
            <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> rows,
            <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> cols
        <font face='Lucida Console'>)</font>;

        <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> <b><a name='number_of_columns'></a>number_of_columns</b> <font face='Lucida Console'>(</font>
        <font face='Lucida Console'>)</font> <font color='#0000FF'>const</font>;

        <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> <b><a name='number_of_rows'></a>number_of_rows</b> <font face='Lucida Console'>(</font>
        <font face='Lucida Console'>)</font> <font color='#0000FF'>const</font>;

        <font color='#0000FF'><u>int</u></font> <b><a name='next_free_user_event_number'></a>next_free_user_event_number</b> <font face='Lucida Console'>(</font>
        <font face='Lucida Console'>)</font> <font color='#0000FF'>const</font>;

        rgb_pixel <b><a name='border_color'></a>border_color</b> <font face='Lucida Console'>(</font>
        <font face='Lucida Console'>)</font> <font color='#0000FF'>const</font>;

        <font color='#0000FF'><u>void</u></font> <b><a name='set_border_color'></a>set_border_color</b> <font face='Lucida Console'>(</font>
            rgb_pixel color
        <font face='Lucida Console'>)</font>;

        <font color='#0000FF'>const</font> std::string <b><a name='text'></a>text</b> <font face='Lucida Console'>(</font>
            <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> row,
            <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> col
        <font face='Lucida Console'>)</font> <font color='#0000FF'>const</font>;

        <font color='#0000FF'>const</font> std::wstring <b><a name='wtext'></a>wtext</b> <font face='Lucida Console'>(</font>
            <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> row,
            <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> col
        <font face='Lucida Console'>)</font> <font color='#0000FF'>const</font>;

        <font color='#0000FF'>const</font> dlib::ustring <b><a name='utext'></a>utext</b> <font face='Lucida Console'>(</font>
            <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> row,
            <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> col
        <font face='Lucida Console'>)</font> <font color='#0000FF'>const</font>;

        <font color='#0000FF'><u>void</u></font> <b><a name='set_text'></a>set_text</b> <font face='Lucida Console'>(</font>
            <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> row,
            <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> col,
            <font color='#0000FF'>const</font> std::string<font color='#5555FF'>&amp;</font> str
        <font face='Lucida Console'>)</font>;

        <font color='#0000FF'><u>void</u></font> <b><a name='set_text'></a>set_text</b> <font face='Lucida Console'>(</font>
            <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> row,
            <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> col,
            <font color='#0000FF'>const</font> std::wstring<font color='#5555FF'>&amp;</font> str
        <font face='Lucida Console'>)</font>;

        <font color='#0000FF'><u>void</u></font> <b><a name='set_text'></a>set_text</b> <font face='Lucida Console'>(</font>
            <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> row,
            <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> col,
            <font color='#0000FF'>const</font> dlib::ustring<font color='#5555FF'>&amp;</font> str
        <font face='Lucida Console'>)</font>;

        <font color='#0000FF'>const</font> rgb_pixel <b><a name='text_color'></a>text_color</b> <font face='Lucida Console'>(</font>
            <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> row,
            <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> col
        <font face='Lucida Console'>)</font> <font color='#0000FF'>const</font>;

        <font color='#0000FF'><u>void</u></font> <b><a name='set_text_color'></a>set_text_color</b> <font face='Lucida Console'>(</font>
            <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> row,
            <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> col,
            <font color='#0000FF'>const</font> rgb_pixel color
        <font face='Lucida Console'>)</font>;

        <font color='#0000FF'>const</font> rgb_pixel <b><a name='background_color'></a>background_color</b> <font face='Lucida Console'>(</font>
            <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> row,
            <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> col
        <font face='Lucida Console'>)</font> <font color='#0000FF'>const</font>;

        <font color='#0000FF'><u>void</u></font> <b><a name='set_background_color'></a>set_background_color</b> <font face='Lucida Console'>(</font>
            <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> row,
            <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> col,
            <font color='#0000FF'>const</font> rgb_pixel color
        <font face='Lucida Console'>)</font>;

        <font color='#0000FF'><u>bool</u></font> <b><a name='is_editable'></a>is_editable</b> <font face='Lucida Console'>(</font>
            <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> row,
            <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> col
        <font face='Lucida Console'>)</font> <font color='#0000FF'>const</font>;

        <font color='#0000FF'><u>void</u></font> <b><a name='set_editable'></a>set_editable</b> <font face='Lucida Console'>(</font>
            <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> row,
            <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> col,
            <font color='#0000FF'><u>bool</u></font> editable
        <font face='Lucida Console'>)</font>;

        <font color='#0000FF'><u>void</u></font> <b><a name='set_column_width'></a>set_column_width</b> <font face='Lucida Console'>(</font>
            <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> col,
            <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> width
        <font face='Lucida Console'>)</font>;

        <font color='#0000FF'><u>void</u></font> <b><a name='set_row_height'></a>set_row_height</b> <font face='Lucida Console'>(</font>
            <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> row,
            <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> height 
        <font face='Lucida Console'>)</font>;

        <font color='#0000FF'><u>void</u></font> <b><a name='disable'></a>disable</b> <font face='Lucida Console'>(</font>
        <font face='Lucida Console'>)</font>;

        <font color='#0000FF'><u>void</u></font> <b><a name='hide'></a>hide</b> <font face='Lucida Console'>(</font>
        <font face='Lucida Console'>)</font>;

        <font color='#0000FF'>template</font> <font color='#5555FF'>&lt;</font>
            <font color='#0000FF'>typename</font> T
            <font color='#5555FF'>&gt;</font>
        <font color='#0000FF'><u>void</u></font> <b><a name='set_text_modified_handler'></a>set_text_modified_handler</b> <font face='Lucida Console'>(</font>
            T<font color='#5555FF'>&amp;</font> object,
            <font color='#0000FF'><u>void</u></font> <font face='Lucida Console'>(</font>T::<font color='#5555FF'>*</font>eh<font face='Lucida Console'>)</font><font face='Lucida Console'>(</font><font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font>, <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font><font face='Lucida Console'>)</font>
        <font face='Lucida Console'>)</font> <b>{</b> text_modified_handler <font color='#5555FF'>=</font> <font color='#BB00BB'>make_mfp</font><font face='Lucida Console'>(</font>object,eh<font face='Lucida Console'>)</font>; <b>}</b>

        <font color='#0000FF'><u>void</u></font> <b><a name='set_text_modified_handler'></a>set_text_modified_handler</b> <font face='Lucida Console'>(</font>
            <font color='#0000FF'>const</font> any_function<font color='#5555FF'>&lt;</font><font color='#0000FF'><u>void</u></font><font face='Lucida Console'>(</font><font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font>, <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font><font face='Lucida Console'>)</font><font color='#5555FF'>&gt;</font><font color='#5555FF'>&amp;</font> eh
        <font face='Lucida Console'>)</font> <b>{</b> text_modified_handler <font color='#5555FF'>=</font> eh; <b>}</b>

    <font color='#0000FF'>private</font>:

        <font color='#0000FF'><u>void</u></font> <b><a name='on_user_event'></a>on_user_event</b> <font face='Lucida Console'>(</font>
            <font color='#0000FF'><u>int</u></font> num
        <font face='Lucida Console'>)</font>;

        <font color='#0000FF'><u>void</u></font> <b><a name='timer_action'></a>timer_action</b> <font face='Lucida Console'>(</font>
        <font face='Lucida Console'>)</font>; 
        <font color='#009900'>/*!
            ensures
                - flips the state of show_cursor 
        !*/</font>

        <font color='#0000FF'><u>void</u></font> <b><a name='compute_bg_rects'></a>compute_bg_rects</b> <font face='Lucida Console'>(</font>
        <font face='Lucida Console'>)</font>;

        <font color='#0000FF'><u>void</u></font> <b><a name='compute_total_rect'></a>compute_total_rect</b> <font face='Lucida Console'>(</font>
        <font face='Lucida Console'>)</font>;

        <font color='#0000FF'><u>void</u></font> <b><a name='on_keydown'></a>on_keydown</b> <font face='Lucida Console'>(</font>
            <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> key,          
            <font color='#0000FF'><u>bool</u></font> is_printable,
            <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> state
        <font face='Lucida Console'>)</font>;

        <font color='#0000FF'><u>void</u></font> <b><a name='on_mouse_down'></a>on_mouse_down</b> <font face='Lucida Console'>(</font>
            <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> btn,
            <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> state,
            <font color='#0000FF'><u>long</u></font> x,
            <font color='#0000FF'><u>long</u></font> y,
            <font color='#0000FF'><u>bool</u></font> is_double_click
        <font face='Lucida Console'>)</font>;

        <font color='#0000FF'><u>void</u></font> <b><a name='on_mouse_up'></a>on_mouse_up</b> <font face='Lucida Console'>(</font>
            <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> btn,
            <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> state,
            <font color='#0000FF'><u>long</u></font> x,
            <font color='#0000FF'><u>long</u></font> y
        <font face='Lucida Console'>)</font>;

        <font color='#0000FF'><u>void</u></font> <b><a name='on_focus_lost'></a>on_focus_lost</b> <font face='Lucida Console'>(</font>
        <font face='Lucida Console'>)</font>;

        <font color='#0000FF'><u>void</u></font> <b><a name='draw'></a>draw</b> <font face='Lucida Console'>(</font>
            <font color='#0000FF'>const</font> canvas<font color='#5555FF'>&amp;</font> c
        <font face='Lucida Console'>)</font> <font color='#0000FF'>const</font>;

        rectangle <b><a name='get_text_rect'></a>get_text_rect</b> <font face='Lucida Console'>(</font>
            <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> row,
            <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> col
        <font face='Lucida Console'>)</font> <font color='#0000FF'>const</font>;

        rectangle <b><a name='get_bg_rect'></a>get_bg_rect</b> <font face='Lucida Console'>(</font>
            <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> row,
            <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> col
        <font face='Lucida Console'>)</font> <font color='#0000FF'>const</font>;

        <font color='#0000FF'>struct</font> <b><a name='data_type'></a>data_type</b>
        <b>{</b>
            <b><a name='data_type'></a>data_type</b><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>: text_color<font face='Lucida Console'>(</font><font color='#979000'>0</font>,<font color='#979000'>0</font>,<font color='#979000'>0</font><font face='Lucida Console'>)</font>, bg_color<font face='Lucida Console'>(</font><font color='#979000'>255</font>,<font color='#979000'>255</font>,<font color='#979000'>255</font><font face='Lucida Console'>)</font>,
            first<font face='Lucida Console'>(</font><font color='#979000'>0</font><font face='Lucida Console'>)</font>, is_editable<font face='Lucida Console'>(</font><font color='#979000'>true</font><font face='Lucida Console'>)</font> 
            <b>{</b><b>}</b>

            dlib::ustring text;
            rgb_pixel text_color;
            rgb_pixel bg_color;
            rectangle bg_rect;
            dlib::ustring::size_type first;
            <font color='#0000FF'><u>bool</u></font> is_editable;
        <b>}</b>;

        <font color='#0000FF'><u>void</u></font> <b><a name='drop_input_focus'></a>drop_input_focus</b> <font face='Lucida Console'>(</font>
        <font face='Lucida Console'>)</font>;

        <font color='#0000FF'><u>void</u></font> <b><a name='move_cursor'></a>move_cursor</b> <font face='Lucida Console'>(</font>
            <font color='#0000FF'><u>long</u></font> row,
            <font color='#0000FF'><u>long</u></font> col,
            <font color='#0000FF'><u>long</u></font> new_cursor_pos
        <font face='Lucida Console'>)</font>;

        array2d<font color='#5555FF'>&lt;</font>data_type<font color='#5555FF'>&gt;</font> grid;
        array<font color='#5555FF'>&lt;</font><font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font><font color='#5555FF'>&gt;</font> col_width;
        array<font color='#5555FF'>&lt;</font><font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font><font color='#5555FF'>&gt;</font> row_height;
        <font color='#0000FF'><u>bool</u></font> has_focus;
        <font color='#0000FF'><u>long</u></font> active_col;
        <font color='#0000FF'><u>long</u></font> active_row;
        <font color='#0000FF'><u>long</u></font> cursor_pos;
        <font color='#0000FF'><u>bool</u></font> show_cursor;
        <font color='#0000FF'><u>bool</u></font> recent_cursor_move;
        timer<font color='#5555FF'>&lt;</font>text_grid<font color='#5555FF'>&gt;</font> cursor_timer;
        rgb_pixel border_color_;
        any_function<font color='#5555FF'>&lt;</font><font color='#0000FF'><u>void</u></font><font face='Lucida Console'>(</font><font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font>, <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font><font face='Lucida Console'>)</font><font color='#5555FF'>&gt;</font> text_modified_handler;
    <b>}</b>;

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'>class</font> <b><a name='image_display'></a>image_display</b> : <font color='#0000FF'>public</font> scrollable_region 
    <b>{</b>
        <font color='#009900'>/*!
            INITIAL VALUE
                - img.size() == 0
                - overlay_rects.size() == 0
                - overlay_lines.size() == 0
                - drawing_rect == false
                - rect_is_selected == false

            CONVENTION
                - img == the image this object displays
                - overlay_rects == the overlay rectangles this object displays
                - overlay_lines == the overlay lines this object displays

                - if (drawing_rect) then
                    - the user is drawing a rectangle on the screen and is
                      thus holding down CTRL and the left mouse button.
                    - rect_anchor == the point on the screen where the user
                      clicked to begin drawing the rectangle.  
                    - rect_to_draw == the rectangle which should appear on the screen.

                - if (rect_is_selected) then
                    - selected_rect == the index in overlay_rects of the user selected
                      rectangle.
                    - last_right_click_pos == the last place we saw the user right click
                      the mouse.
                    - parts_menu.is_enabled() == true
                    - if (it is actually a part of this rect that is selected) then
                        - selected_part_name == the name of the part in overlay_rects[selected_rect].parts
                          that is selected.
                    - else
                        - selected_part_name.size() == 0
                - else
                    - parts_menu.is_enabled() == false
                    - selected_part_name.size() == 0
        !*/</font>

    <font color='#0000FF'>public</font>:

        <b><a name='image_display'></a>image_display</b><font face='Lucida Console'>(</font>  
            drawable_window<font color='#5555FF'>&amp;</font> w
        <font face='Lucida Console'>)</font>;

        ~<b><a name='image_display'></a>image_display</b><font face='Lucida Console'>(</font>
        <font face='Lucida Console'>)</font>;

        <font color='#0000FF'>template</font> <font color='#5555FF'>&lt;</font>
            <font color='#0000FF'>typename</font> image_type
            <font color='#5555FF'>&gt;</font>
        <font color='#0000FF'><u>void</u></font> <b><a name='set_image'></a>set_image</b> <font face='Lucida Console'>(</font>
            <font color='#0000FF'>const</font> image_type<font color='#5555FF'>&amp;</font> new_img
        <font face='Lucida Console'>)</font>
        <b>{</b>
            auto_mutex <font color='#BB00BB'>M</font><font face='Lucida Console'>(</font>m<font face='Lucida Console'>)</font>;

            <font color='#009900'>// if the new image has a different size when compared to the previous image
</font>            <font color='#009900'>// then we should readjust the total rectangle size.
</font>            <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>new_img.<font color='#BB00BB'>nr</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>!</font><font color='#5555FF'>=</font> img.<font color='#BB00BB'>nr</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>|</font><font color='#5555FF'>|</font> new_img.<font color='#BB00BB'>nc</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>!</font><font color='#5555FF'>=</font> img.<font color='#BB00BB'>nc</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>
            <b>{</b>
                <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>zoom_in_scale <font color='#5555FF'>!</font><font color='#5555FF'>=</font> <font color='#979000'>1</font><font face='Lucida Console'>)</font>
                    <font color='#BB00BB'>set_total_rect_size</font><font face='Lucida Console'>(</font>new_img.<font color='#BB00BB'>nc</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>*</font>zoom_in_scale, new_img.<font color='#BB00BB'>nr</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>*</font>zoom_in_scale<font face='Lucida Console'>)</font>;
                <font color='#0000FF'>else</font>
                    <font color='#BB00BB'>set_total_rect_size</font><font face='Lucida Console'>(</font>new_img.<font color='#BB00BB'>nc</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>/</font>zoom_out_scale, new_img.<font color='#BB00BB'>nr</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>/</font>zoom_out_scale<font face='Lucida Console'>)</font>;
            <b>}</b>
            <font color='#0000FF'>else</font>
            <b>{</b>
                parent.<font color='#BB00BB'>invalidate_rectangle</font><font face='Lucida Console'>(</font>rect<font face='Lucida Console'>)</font>;
            <b>}</b>

            highlighted_rect <font color='#5555FF'>=</font> std::numeric_limits<font color='#5555FF'>&lt;</font><font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font><font color='#5555FF'>&gt;</font>::<font color='#BB00BB'>max</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
            rect_is_selected <font color='#5555FF'>=</font> <font color='#979000'>false</font>;
            parts_menu.<font color='#BB00BB'>disable</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
            <font color='#BB00BB'>assign_image_scaled</font><font face='Lucida Console'>(</font>img,new_img<font face='Lucida Console'>)</font>;
        <b>}</b>

        <font color='#0000FF'>virtual</font> <font color='#0000FF'><u>void</u></font> <b><a name='set_pos'></a>set_pos</b> <font face='Lucida Console'>(</font>
            <font color='#0000FF'><u>long</u></font> x,
            <font color='#0000FF'><u>long</u></font> y
        <font face='Lucida Console'>)</font>
        <b>{</b>
            auto_mutex <font color='#BB00BB'>lock</font><font face='Lucida Console'>(</font>m<font face='Lucida Console'>)</font>;
            scrollable_region::<font color='#BB00BB'>set_pos</font><font face='Lucida Console'>(</font>x,y<font face='Lucida Console'>)</font>;
            parts_menu.<font color='#BB00BB'>set_rect</font><font face='Lucida Console'>(</font>rect<font face='Lucida Console'>)</font>;
        <b>}</b>

        <font color='#0000FF'>virtual</font> <font color='#0000FF'><u>void</u></font> <b><a name='set_size'></a>set_size</b> <font face='Lucida Console'>(</font>
            <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> width,
            <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> height 
        <font face='Lucida Console'>)</font>
        <b>{</b>
            auto_mutex <font color='#BB00BB'>lock</font><font face='Lucida Console'>(</font>m<font face='Lucida Console'>)</font>;
            scrollable_region::<font color='#BB00BB'>set_size</font><font face='Lucida Console'>(</font>width,height<font face='Lucida Console'>)</font>;
            parts_menu.<font color='#BB00BB'>set_rect</font><font face='Lucida Console'>(</font>rect<font face='Lucida Console'>)</font>;
        <b>}</b>

        <font color='#0000FF'>struct</font> <b><a name='overlay_rect'></a>overlay_rect</b>
        <b>{</b>
            <b><a name='overlay_rect'></a>overlay_rect</b><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> :crossed_out<font face='Lucida Console'>(</font><font color='#979000'>false</font><font face='Lucida Console'>)</font> <b>{</b> <font color='#BB00BB'>assign_pixel</font><font face='Lucida Console'>(</font>color, <font color='#979000'>0</font><font face='Lucida Console'>)</font>;<b>}</b>

            <font color='#0000FF'>template</font> <font color='#5555FF'>&lt;</font><font color='#0000FF'>typename</font> pixel_type<font color='#5555FF'>&gt;</font>
            <b><a name='overlay_rect'></a>overlay_rect</b><font face='Lucida Console'>(</font><font color='#0000FF'>const</font> rectangle<font color='#5555FF'>&amp;</font> r, pixel_type p<font face='Lucida Console'>)</font> 
                : rect<font face='Lucida Console'>(</font>r<font face='Lucida Console'>)</font>,crossed_out<font face='Lucida Console'>(</font><font color='#979000'>false</font><font face='Lucida Console'>)</font> <b>{</b> <font color='#BB00BB'>assign_pixel</font><font face='Lucida Console'>(</font>color, p<font face='Lucida Console'>)</font>; <b>}</b>

            <font color='#0000FF'>template</font> <font color='#5555FF'>&lt;</font><font color='#0000FF'>typename</font> pixel_type<font color='#5555FF'>&gt;</font>
            <b><a name='overlay_rect'></a>overlay_rect</b><font face='Lucida Console'>(</font><font color='#0000FF'>const</font> rectangle<font color='#5555FF'>&amp;</font> r, pixel_type p, <font color='#0000FF'>const</font> std::string<font color='#5555FF'>&amp;</font> l<font face='Lucida Console'>)</font> 
                : rect<font face='Lucida Console'>(</font>r<font face='Lucida Console'>)</font>,label<font face='Lucida Console'>(</font>l<font face='Lucida Console'>)</font>,crossed_out<font face='Lucida Console'>(</font><font color='#979000'>false</font><font face='Lucida Console'>)</font> <b>{</b> <font color='#BB00BB'>assign_pixel</font><font face='Lucida Console'>(</font>color, p<font face='Lucida Console'>)</font>; <b>}</b>

            <font color='#0000FF'>template</font> <font color='#5555FF'>&lt;</font><font color='#0000FF'>typename</font> pixel_type<font color='#5555FF'>&gt;</font>
            <b><a name='overlay_rect'></a>overlay_rect</b><font face='Lucida Console'>(</font><font color='#0000FF'>const</font> rectangle<font color='#5555FF'>&amp;</font> r, pixel_type p, <font color='#0000FF'>const</font> std::string<font color='#5555FF'>&amp;</font> l, <font color='#0000FF'>const</font> std::map<font color='#5555FF'>&lt;</font>std::string,point<font color='#5555FF'>&gt;</font><font color='#5555FF'>&amp;</font> parts_<font face='Lucida Console'>)</font> 
                : rect<font face='Lucida Console'>(</font>r<font face='Lucida Console'>)</font>,label<font face='Lucida Console'>(</font>l<font face='Lucida Console'>)</font>,parts<font face='Lucida Console'>(</font>parts_<font face='Lucida Console'>)</font>,crossed_out<font face='Lucida Console'>(</font><font color='#979000'>false</font><font face='Lucida Console'>)</font> <b>{</b> <font color='#BB00BB'>assign_pixel</font><font face='Lucida Console'>(</font>color, p<font face='Lucida Console'>)</font>; <b>}</b>

            rectangle rect;
            rgb_alpha_pixel color;
            std::string label;
            std::map<font color='#5555FF'>&lt;</font>std::string,point<font color='#5555FF'>&gt;</font> parts;
            <font color='#0000FF'><u>bool</u></font> crossed_out;
        <b>}</b>;

        <font color='#0000FF'>struct</font> <b><a name='overlay_line'></a>overlay_line</b>
        <b>{</b>
            <b><a name='overlay_line'></a>overlay_line</b><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <b>{</b> <font color='#BB00BB'>assign_pixel</font><font face='Lucida Console'>(</font>color, <font color='#979000'>0</font><font face='Lucida Console'>)</font>;<b>}</b>

            <font color='#0000FF'>template</font> <font color='#5555FF'>&lt;</font><font color='#0000FF'>typename</font> pixel_type<font color='#5555FF'>&gt;</font>
            <b><a name='overlay_line'></a>overlay_line</b><font face='Lucida Console'>(</font><font color='#0000FF'>const</font> point<font color='#5555FF'>&amp;</font> p1_, <font color='#0000FF'>const</font> point<font color='#5555FF'>&amp;</font> p2_, pixel_type p<font face='Lucida Console'>)</font> 
                : p1<font face='Lucida Console'>(</font>p1_<font face='Lucida Console'>)</font>, p2<font face='Lucida Console'>(</font>p2_<font face='Lucida Console'>)</font> <b>{</b> <font color='#BB00BB'>assign_pixel</font><font face='Lucida Console'>(</font>color, p<font face='Lucida Console'>)</font>; <b>}</b>

            point p1;
            point p2;
            rgb_alpha_pixel color;
        <b>}</b>;

        <font color='#0000FF'>struct</font> <b><a name='overlay_circle'></a>overlay_circle</b>
        <b>{</b>
            <b><a name='overlay_circle'></a>overlay_circle</b><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>:radius<font face='Lucida Console'>(</font><font color='#979000'>0</font><font face='Lucida Console'>)</font> <b>{</b> <font color='#BB00BB'>assign_pixel</font><font face='Lucida Console'>(</font>color, <font color='#979000'>0</font><font face='Lucida Console'>)</font>;<b>}</b>

            <font color='#0000FF'>template</font> <font color='#5555FF'>&lt;</font><font color='#0000FF'>typename</font> pixel_type<font color='#5555FF'>&gt;</font>
            <b><a name='overlay_circle'></a>overlay_circle</b><font face='Lucida Console'>(</font><font color='#0000FF'>const</font> point<font color='#5555FF'>&amp;</font> center_, <font color='#0000FF'>const</font> <font color='#0000FF'><u>int</u></font> radius_, pixel_type p<font face='Lucida Console'>)</font> 
                : center<font face='Lucida Console'>(</font>center_<font face='Lucida Console'>)</font>, radius<font face='Lucida Console'>(</font>radius_<font face='Lucida Console'>)</font> <b>{</b> <font color='#BB00BB'>assign_pixel</font><font face='Lucida Console'>(</font>color, p<font face='Lucida Console'>)</font>; <b>}</b>

            <font color='#0000FF'>template</font> <font color='#5555FF'>&lt;</font><font color='#0000FF'>typename</font> pixel_type<font color='#5555FF'>&gt;</font>
            <b><a name='overlay_circle'></a>overlay_circle</b><font face='Lucida Console'>(</font><font color='#0000FF'>const</font> point<font color='#5555FF'>&amp;</font> center_, <font color='#0000FF'>const</font> <font color='#0000FF'><u>int</u></font> radius_, pixel_type p, <font color='#0000FF'>const</font> std::string<font color='#5555FF'>&amp;</font> l<font face='Lucida Console'>)</font> 
                : center<font face='Lucida Console'>(</font>center_<font face='Lucida Console'>)</font>, radius<font face='Lucida Console'>(</font>radius_<font face='Lucida Console'>)</font>, label<font face='Lucida Console'>(</font>l<font face='Lucida Console'>)</font> <b>{</b> <font color='#BB00BB'>assign_pixel</font><font face='Lucida Console'>(</font>color, p<font face='Lucida Console'>)</font>; <b>}</b>

            point center;
            <font color='#0000FF'><u>int</u></font> radius;
            rgb_alpha_pixel color;
            std::string label;
        <b>}</b>;

        <font color='#0000FF'><u>void</u></font> <b><a name='add_overlay'></a>add_overlay</b> <font face='Lucida Console'>(</font>
            <font color='#0000FF'>const</font> overlay_rect<font color='#5555FF'>&amp;</font> overlay
        <font face='Lucida Console'>)</font>;

        <font color='#0000FF'><u>void</u></font> <b><a name='add_overlay'></a>add_overlay</b> <font face='Lucida Console'>(</font>
            <font color='#0000FF'>const</font> overlay_line<font color='#5555FF'>&amp;</font> overlay
        <font face='Lucida Console'>)</font>;

        <font color='#0000FF'><u>void</u></font> <b><a name='add_overlay'></a>add_overlay</b> <font face='Lucida Console'>(</font>
            <font color='#0000FF'>const</font> overlay_circle<font color='#5555FF'>&amp;</font> overlay
        <font face='Lucida Console'>)</font>;

        <font color='#0000FF'><u>void</u></font> <b><a name='add_overlay'></a>add_overlay</b> <font face='Lucida Console'>(</font>
            <font color='#0000FF'>const</font> std::vector<font color='#5555FF'>&lt;</font>overlay_rect<font color='#5555FF'>&gt;</font><font color='#5555FF'>&amp;</font> overlay
        <font face='Lucida Console'>)</font>;

        <font color='#0000FF'><u>void</u></font> <b><a name='add_overlay'></a>add_overlay</b> <font face='Lucida Console'>(</font>
            <font color='#0000FF'>const</font> std::vector<font color='#5555FF'>&lt;</font>overlay_line<font color='#5555FF'>&gt;</font><font color='#5555FF'>&amp;</font> overlay
        <font face='Lucida Console'>)</font>;

        <font color='#0000FF'><u>void</u></font> <b><a name='add_overlay'></a>add_overlay</b> <font face='Lucida Console'>(</font>
            <font color='#0000FF'>const</font> std::vector<font color='#5555FF'>&lt;</font>overlay_circle<font color='#5555FF'>&gt;</font><font color='#5555FF'>&amp;</font> overlay
        <font face='Lucida Console'>)</font>;

        <font color='#0000FF'><u>void</u></font> <b><a name='clear_overlay'></a>clear_overlay</b> <font face='Lucida Console'>(</font>
        <font face='Lucida Console'>)</font>;

        rectangle <b><a name='get_image_display_rect'></a>get_image_display_rect</b> <font face='Lucida Console'>(</font>
        <font face='Lucida Console'>)</font> <font color='#0000FF'>const</font>;

        std::vector<font color='#5555FF'>&lt;</font>overlay_rect<font color='#5555FF'>&gt;</font> <b><a name='get_overlay_rects'></a>get_overlay_rects</b> <font face='Lucida Console'>(</font>
        <font face='Lucida Console'>)</font> <font color='#0000FF'>const</font>;

        <font color='#0000FF'><u>void</u></font> <b><a name='set_default_overlay_rect_label'></a>set_default_overlay_rect_label</b> <font face='Lucida Console'>(</font>
            <font color='#0000FF'>const</font> std::string<font color='#5555FF'>&amp;</font> label
        <font face='Lucida Console'>)</font>;

        std::string <b><a name='get_default_overlay_rect_label'></a>get_default_overlay_rect_label</b> <font face='Lucida Console'>(</font>
        <font face='Lucida Console'>)</font> <font color='#0000FF'>const</font>;

        <font color='#0000FF'><u>void</u></font> <b><a name='set_default_overlay_rect_color'></a>set_default_overlay_rect_color</b> <font face='Lucida Console'>(</font>
            <font color='#0000FF'>const</font> rgb_alpha_pixel<font color='#5555FF'>&amp;</font> color
        <font face='Lucida Console'>)</font>;

        rgb_alpha_pixel <b><a name='get_default_overlay_rect_color'></a>get_default_overlay_rect_color</b> <font face='Lucida Console'>(</font>
        <font face='Lucida Console'>)</font> <font color='#0000FF'>const</font>;

        <font color='#0000FF'>template</font> <font color='#5555FF'>&lt;</font>
            <font color='#0000FF'>typename</font> T
            <font color='#5555FF'>&gt;</font>
        <font color='#0000FF'><u>void</u></font> <b><a name='set_overlay_rects_changed_handler'></a>set_overlay_rects_changed_handler</b> <font face='Lucida Console'>(</font>
            T<font color='#5555FF'>&amp;</font> object,
            <font color='#0000FF'><u>void</u></font> <font face='Lucida Console'>(</font>T::<font color='#5555FF'>*</font>event_handler_<font face='Lucida Console'>)</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>
        <font face='Lucida Console'>)</font>
        <b>{</b>
            auto_mutex <font color='#BB00BB'>M</font><font face='Lucida Console'>(</font>m<font face='Lucida Console'>)</font>;
            event_handler <font color='#5555FF'>=</font> <font color='#BB00BB'>make_mfp</font><font face='Lucida Console'>(</font>object,event_handler_<font face='Lucida Console'>)</font>;
        <b>}</b>

        <font color='#0000FF'><u>void</u></font> <b><a name='set_overlay_rects_changed_handler'></a>set_overlay_rects_changed_handler</b> <font face='Lucida Console'>(</font>
            <font color='#0000FF'>const</font> any_function<font color='#5555FF'>&lt;</font><font color='#0000FF'><u>void</u></font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>&gt;</font><font color='#5555FF'>&amp;</font> event_handler_
        <font face='Lucida Console'>)</font>
        <b>{</b>
            auto_mutex <font color='#BB00BB'>M</font><font face='Lucida Console'>(</font>m<font face='Lucida Console'>)</font>;
            event_handler <font color='#5555FF'>=</font> event_handler_;
        <b>}</b>

        <font color='#0000FF'>template</font> <font color='#5555FF'>&lt;</font>
            <font color='#0000FF'>typename</font> T
            <font color='#5555FF'>&gt;</font>
        <font color='#0000FF'><u>void</u></font> <b><a name='set_overlay_rect_selected_handler'></a>set_overlay_rect_selected_handler</b> <font face='Lucida Console'>(</font>
            T<font color='#5555FF'>&amp;</font> object,
            <font color='#0000FF'><u>void</u></font> <font face='Lucida Console'>(</font>T::<font color='#5555FF'>*</font>event_handler_<font face='Lucida Console'>)</font><font face='Lucida Console'>(</font><font color='#0000FF'>const</font> overlay_rect<font color='#5555FF'>&amp;</font> orect<font face='Lucida Console'>)</font>
        <font face='Lucida Console'>)</font>
        <b>{</b>
            auto_mutex <font color='#BB00BB'>M</font><font face='Lucida Console'>(</font>m<font face='Lucida Console'>)</font>;
            orect_selected_event_handler <font color='#5555FF'>=</font> <font color='#BB00BB'>make_mfp</font><font face='Lucida Console'>(</font>object,event_handler_<font face='Lucida Console'>)</font>;
        <b>}</b>

        <font color='#0000FF'><u>void</u></font> <b><a name='set_overlay_rect_selected_handler'></a>set_overlay_rect_selected_handler</b> <font face='Lucida Console'>(</font>
            <font color='#0000FF'>const</font> any_function<font color='#5555FF'>&lt;</font><font color='#0000FF'><u>void</u></font><font face='Lucida Console'>(</font><font color='#0000FF'>const</font> overlay_rect<font color='#5555FF'>&amp;</font> orect<font face='Lucida Console'>)</font><font color='#5555FF'>&gt;</font><font color='#5555FF'>&amp;</font> event_handler_
        <font face='Lucida Console'>)</font>
        <b>{</b>
            auto_mutex <font color='#BB00BB'>M</font><font face='Lucida Console'>(</font>m<font face='Lucida Console'>)</font>;
            orect_selected_event_handler <font color='#5555FF'>=</font> event_handler_;
        <b>}</b>

        <font color='#0000FF'>template</font> <font color='#5555FF'>&lt;</font>
            <font color='#0000FF'>typename</font> T
            <font color='#5555FF'>&gt;</font>
        <font color='#0000FF'><u>void</u></font> <b><a name='set_image_clicked_handler'></a>set_image_clicked_handler</b> <font face='Lucida Console'>(</font>
            T<font color='#5555FF'>&amp;</font> object,
            <font color='#0000FF'><u>void</u></font> <font face='Lucida Console'>(</font>T::<font color='#5555FF'>*</font>event_handler_<font face='Lucida Console'>)</font><font face='Lucida Console'>(</font><font color='#0000FF'>const</font> point<font color='#5555FF'>&amp;</font> p, <font color='#0000FF'><u>bool</u></font> is_double_click, <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> btn<font face='Lucida Console'>)</font>
        <font face='Lucida Console'>)</font>
        <b>{</b>
            auto_mutex <font color='#BB00BB'>M</font><font face='Lucida Console'>(</font>m<font face='Lucida Console'>)</font>;
            image_clicked_handler <font color='#5555FF'>=</font> <font color='#BB00BB'>make_mfp</font><font face='Lucida Console'>(</font>object,event_handler_<font face='Lucida Console'>)</font>;
        <b>}</b>

        <font color='#0000FF'><u>void</u></font> <b><a name='set_image_clicked_handler'></a>set_image_clicked_handler</b> <font face='Lucida Console'>(</font>
            <font color='#0000FF'>const</font> any_function<font color='#5555FF'>&lt;</font><font color='#0000FF'><u>void</u></font><font face='Lucida Console'>(</font><font color='#0000FF'>const</font> point<font color='#5555FF'>&amp;</font> p, <font color='#0000FF'><u>bool</u></font> is_double_click, <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> btn<font face='Lucida Console'>)</font><font color='#5555FF'>&gt;</font><font color='#5555FF'>&amp;</font> event_handler_
        <font face='Lucida Console'>)</font>
        <b>{</b>
            auto_mutex <font color='#BB00BB'>M</font><font face='Lucida Console'>(</font>m<font face='Lucida Console'>)</font>;
            image_clicked_handler <font color='#5555FF'>=</font> event_handler_;
        <b>}</b>

        <font color='#0000FF'><u>void</u></font> <b><a name='add_labelable_part_name'></a>add_labelable_part_name</b> <font face='Lucida Console'>(</font>
            <font color='#0000FF'>const</font> std::string<font color='#5555FF'>&amp;</font> name
        <font face='Lucida Console'>)</font>;

        <font color='#0000FF'><u>void</u></font> <b><a name='clear_labelable_part_names'></a>clear_labelable_part_names</b> <font face='Lucida Console'>(</font>
        <font face='Lucida Console'>)</font>;

        <font color='#0000FF'><u>void</u></font> <b><a name='enable_overlay_editing'></a>enable_overlay_editing</b> <font face='Lucida Console'>(</font>
        <font face='Lucida Console'>)</font> <b>{</b> auto_mutex <font color='#BB00BB'>M</font><font face='Lucida Console'>(</font>m<font face='Lucida Console'>)</font>; overlay_editing_enabled <font color='#5555FF'>=</font> <font color='#979000'>true</font>; <b>}</b>

        <font color='#0000FF'><u>void</u></font> <b><a name='disable_overlay_editing'></a>disable_overlay_editing</b> <font face='Lucida Console'>(</font>
        <font face='Lucida Console'>)</font> 
        <b>{</b> 
            auto_mutex <font color='#BB00BB'>M</font><font face='Lucida Console'>(</font>m<font face='Lucida Console'>)</font>; 
            overlay_editing_enabled <font color='#5555FF'>=</font> <font color='#979000'>false</font>;  
            rect_is_selected <font color='#5555FF'>=</font> <font color='#979000'>false</font>;
            drawing_rect <font color='#5555FF'>=</font> <font color='#979000'>false</font>;
            parent.<font color='#BB00BB'>invalidate_rectangle</font><font face='Lucida Console'>(</font>rect<font face='Lucida Console'>)</font>;
        <b>}</b>
        
        <font color='#0000FF'><u>bool</u></font> <b><a name='overlay_editing_is_enabled'></a>overlay_editing_is_enabled</b> <font face='Lucida Console'>(</font>
        <font face='Lucida Console'>)</font> <font color='#0000FF'>const</font> <b>{</b> auto_mutex <font color='#BB00BB'>M</font><font face='Lucida Console'>(</font>m<font face='Lucida Console'>)</font>; <font color='#0000FF'>return</font> overlay_editing_enabled; <b>}</b>

    <font color='#0000FF'>private</font>:

        <font color='#0000FF'><u>void</u></font> <b><a name='draw'></a>draw</b> <font face='Lucida Console'>(</font>
            <font color='#0000FF'>const</font> canvas<font color='#5555FF'>&amp;</font> c
        <font face='Lucida Console'>)</font> <font color='#0000FF'>const</font>;

        <font color='#0000FF'><u>void</u></font> <b><a name='on_wheel_up'></a>on_wheel_up</b> <font face='Lucida Console'>(</font>
            <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> state
        <font face='Lucida Console'>)</font>;

        <font color='#0000FF'><u>void</u></font> <b><a name='on_wheel_down'></a>on_wheel_down</b> <font face='Lucida Console'>(</font>
            <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> state
        <font face='Lucida Console'>)</font>;

        <font color='#0000FF'><u>void</u></font> <b><a name='on_mouse_down'></a>on_mouse_down</b> <font face='Lucida Console'>(</font>
            <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> btn,
            <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> state,
            <font color='#0000FF'><u>long</u></font> x,
            <font color='#0000FF'><u>long</u></font> y,
            <font color='#0000FF'><u>bool</u></font> is_double_click
        <font face='Lucida Console'>)</font>;

        <font color='#0000FF'><u>void</u></font> <b><a name='on_mouse_up'></a>on_mouse_up</b> <font face='Lucida Console'>(</font>
            <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> btn,
            <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> state,
            <font color='#0000FF'><u>long</u></font> x,
            <font color='#0000FF'><u>long</u></font> y
        <font face='Lucida Console'>)</font>;

        <font color='#0000FF'><u>void</u></font> <b><a name='on_mouse_move'></a>on_mouse_move</b> <font face='Lucida Console'>(</font>
            <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> state,
            <font color='#0000FF'><u>long</u></font> x,
            <font color='#0000FF'><u>long</u></font> y
        <font face='Lucida Console'>)</font>;

        <font color='#0000FF'><u>void</u></font> <b><a name='on_keydown'></a>on_keydown</b> <font face='Lucida Console'>(</font>
            <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> key,
            <font color='#0000FF'><u>bool</u></font> is_printable,
            <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> state
        <font face='Lucida Console'>)</font>;

        <font color='#0000FF'><u>void</u></font> <b><a name='on_part_add'></a>on_part_add</b> <font face='Lucida Console'>(</font>
            <font color='#0000FF'>const</font> std::string<font color='#5555FF'>&amp;</font> part_name
        <font face='Lucida Console'>)</font>;

        rectangle <b><a name='get_rect_on_screen'></a>get_rect_on_screen</b> <font face='Lucida Console'>(</font>
            <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> idx
        <font face='Lucida Console'>)</font> <font color='#0000FF'>const</font>;

        rectangle <b><a name='get_rect_on_screen'></a>get_rect_on_screen</b> <font face='Lucida Console'>(</font>
            rectangle orect 
        <font face='Lucida Console'>)</font> <font color='#0000FF'>const</font>;

        rgb_alpha_pixel <b><a name='invert_pixel'></a>invert_pixel</b> <font face='Lucida Console'>(</font><font color='#0000FF'>const</font> rgb_alpha_pixel<font color='#5555FF'>&amp;</font> p<font face='Lucida Console'>)</font> <font color='#0000FF'>const</font>
        <b>{</b> <font color='#0000FF'>return</font> <font color='#BB00BB'>rgb_alpha_pixel</font><font face='Lucida Console'>(</font><font color='#979000'>255</font><font color='#5555FF'>-</font>p.red, <font color='#979000'>255</font><font color='#5555FF'>-</font>p.green, <font color='#979000'>255</font><font color='#5555FF'>-</font>p.blue, p.alpha<font face='Lucida Console'>)</font>; <b>}</b>

        <font color='#0000FF'>virtual</font> <font color='#0000FF'><u>int</u></font> <b><a name='next_free_user_event_number'></a>next_free_user_event_number</b> <font face='Lucida Console'>(</font>
        <font face='Lucida Console'>)</font> <font color='#0000FF'>const</font> <b>{</b> <font color='#0000FF'>return</font> scrollable_region::<font color='#BB00BB'>next_free_user_event_number</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>+</font><font color='#979000'>1</font>; <b>}</b>
        <font color='#009900'>// The reason for using user actions here rather than just having the timer just call
</font>        <font color='#009900'>// what it needs directly is to avoid a potential deadlock during destruction of this widget.
</font>        <font color='#0000FF'><u>void</u></font> <b><a name='timer_event_unhighlight_rect'></a>timer_event_unhighlight_rect</b><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>
        <b>{</b> 
            highlight_timer.<font color='#BB00BB'>stop</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>; 
            parent.<font color='#BB00BB'>trigger_user_event</font><font face='Lucida Console'>(</font><font color='#0000FF'>this</font>,scrollable_region::<font color='#BB00BB'>next_free_user_event_number</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>; 
        <b>}</b>
        <font color='#0000FF'><u>void</u></font> <b><a name='on_user_event'></a>on_user_event</b> <font face='Lucida Console'>(</font><font color='#0000FF'><u>int</u></font> num<font face='Lucida Console'>)</font>
        <b>{</b>
            <font color='#009900'>// ignore this user event if it isn't for us
</font>            <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>num <font color='#5555FF'>!</font><font color='#5555FF'>=</font> scrollable_region::<font color='#BB00BB'>next_free_user_event_number</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>
                <font color='#0000FF'>return</font>;
            <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>highlighted_rect <font color='#5555FF'>&lt;</font> overlay_rects.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>
            <b>{</b>
                highlighted_rect <font color='#5555FF'>=</font> std::numeric_limits<font color='#5555FF'>&lt;</font><font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font><font color='#5555FF'>&gt;</font>::<font color='#BB00BB'>max</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
                parent.<font color='#BB00BB'>invalidate_rectangle</font><font face='Lucida Console'>(</font>rect<font face='Lucida Console'>)</font>;
            <b>}</b>
        <b>}</b>


        array2d<font color='#5555FF'>&lt;</font>rgb_alpha_pixel<font color='#5555FF'>&gt;</font> img;


        std::vector<font color='#5555FF'>&lt;</font>overlay_rect<font color='#5555FF'>&gt;</font> overlay_rects;
        std::vector<font color='#5555FF'>&lt;</font>overlay_line<font color='#5555FF'>&gt;</font> overlay_lines;
        std::vector<font color='#5555FF'>&lt;</font>overlay_circle<font color='#5555FF'>&gt;</font> overlay_circles;

        <font color='#0000FF'><u>long</u></font> zoom_in_scale;
        <font color='#0000FF'><u>long</u></font> zoom_out_scale;
        <font color='#0000FF'><u>bool</u></font> drawing_rect;
        point rect_anchor;
        rectangle rect_to_draw;
        <font color='#0000FF'><u>bool</u></font> rect_is_selected;
        std::string selected_part_name;
        <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> selected_rect;
        rgb_alpha_pixel default_rect_color;
        std::string default_rect_label;
        any_function<font color='#5555FF'>&lt;</font><font color='#0000FF'><u>void</u></font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>&gt;</font> event_handler;
        any_function<font color='#5555FF'>&lt;</font><font color='#0000FF'><u>void</u></font><font face='Lucida Console'>(</font><font color='#0000FF'>const</font> overlay_rect<font color='#5555FF'>&amp;</font> orect<font face='Lucida Console'>)</font><font color='#5555FF'>&gt;</font> orect_selected_event_handler;
        any_function<font color='#5555FF'>&lt;</font><font color='#0000FF'><u>void</u></font><font face='Lucida Console'>(</font><font color='#0000FF'>const</font> point<font color='#5555FF'>&amp;</font> p, <font color='#0000FF'><u>bool</u></font> is_double_click, <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> btn<font face='Lucida Console'>)</font><font color='#5555FF'>&gt;</font> image_clicked_handler;
        popup_menu_region parts_menu;
        point last_right_click_pos;
        <font color='#0000FF'>const</font> <font color='#0000FF'><u>int</u></font> part_width;
        std::set<font color='#5555FF'>&lt;</font>std::string<font color='#5555FF'>&gt;</font> part_names;
        <font color='#0000FF'><u>bool</u></font> overlay_editing_enabled;
        timer<font color='#5555FF'>&lt;</font>image_display<font color='#5555FF'>&gt;</font> highlight_timer;
        <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> highlighted_rect;

        <font color='#009900'>// restricted functions
</font>        <b><a name='image_display'></a>image_display</b><font face='Lucida Console'>(</font>image_display<font color='#5555FF'>&amp;</font><font face='Lucida Console'>)</font>;        <font color='#009900'>// copy constructor
</font>        image_display<font color='#5555FF'>&amp;</font> <b><a name='operator'></a>operator</b><font color='#5555FF'>=</font><font face='Lucida Console'>(</font>image_display<font color='#5555FF'>&amp;</font><font face='Lucida Console'>)</font>;    <font color='#009900'>// assignment operator
</font>    <b>}</b>;

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'>class</font> <b><a name='image_window'></a>image_window</b> : <font color='#0000FF'>public</font> drawable_window 
    <b>{</b>
    <font color='#0000FF'>public</font>:

        <font color='#0000FF'>typedef</font> image_display::overlay_rect overlay_rect;
        <font color='#0000FF'>typedef</font> image_display::overlay_line overlay_line;
        <font color='#0000FF'>typedef</font> image_display::overlay_circle overlay_circle;

        <b><a name='image_window'></a>image_window</b><font face='Lucida Console'>(</font>
        <font face='Lucida Console'>)</font>; 

        <font color='#0000FF'>template</font> <font color='#5555FF'>&lt;</font> <font color='#0000FF'>typename</font> image_type <font color='#5555FF'>&gt;</font>
        <b><a name='image_window'></a>image_window</b><font face='Lucida Console'>(</font>
            <font color='#0000FF'>const</font> image_type<font color='#5555FF'>&amp;</font> img
        <font face='Lucida Console'>)</font> : 
            gui_img<font face='Lucida Console'>(</font><font color='#5555FF'>*</font><font color='#0000FF'>this</font><font face='Lucida Console'>)</font>, 
            window_has_closed<font face='Lucida Console'>(</font><font color='#979000'>false</font><font face='Lucida Console'>)</font>,
            have_last_click<font face='Lucida Console'>(</font><font color='#979000'>false</font><font face='Lucida Console'>)</font>,
            mouse_btn<font face='Lucida Console'>(</font><font color='#979000'>0</font><font face='Lucida Console'>)</font>,
            clicked_signaler<font face='Lucida Console'>(</font><font color='#0000FF'>this</font><font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>wm<font face='Lucida Console'>)</font>,
            have_last_keypress<font face='Lucida Console'>(</font><font color='#979000'>false</font><font face='Lucida Console'>)</font>,
            tie_input_events<font face='Lucida Console'>(</font><font color='#979000'>false</font><font face='Lucida Console'>)</font>
        <b>{</b>  
            gui_img.<font color='#BB00BB'>set_image_clicked_handler</font><font face='Lucida Console'>(</font><font color='#5555FF'>*</font><font color='#0000FF'>this</font>, <font color='#5555FF'>&amp;</font>image_window::on_image_clicked<font face='Lucida Console'>)</font>;
            gui_img.<font color='#BB00BB'>disable_overlay_editing</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
            <font color='#BB00BB'>set_image</font><font face='Lucida Console'>(</font>img<font face='Lucida Console'>)</font>; 
            <font color='#BB00BB'>show</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>; 
        <b>}</b>
        
        <font color='#0000FF'>template</font> <font color='#5555FF'>&lt;</font> <font color='#0000FF'>typename</font> image_type <font color='#5555FF'>&gt;</font>
        <b><a name='image_window'></a>image_window</b><font face='Lucida Console'>(</font>
            <font color='#0000FF'>const</font> image_type<font color='#5555FF'>&amp;</font> img,
            <font color='#0000FF'>const</font> std::string<font color='#5555FF'>&amp;</font> title
        <font face='Lucida Console'>)</font> : 
            gui_img<font face='Lucida Console'>(</font><font color='#5555FF'>*</font><font color='#0000FF'>this</font><font face='Lucida Console'>)</font>, 
            window_has_closed<font face='Lucida Console'>(</font><font color='#979000'>false</font><font face='Lucida Console'>)</font>,
            have_last_click<font face='Lucida Console'>(</font><font color='#979000'>false</font><font face='Lucida Console'>)</font>,
            mouse_btn<font face='Lucida Console'>(</font><font color='#979000'>0</font><font face='Lucida Console'>)</font>,
            clicked_signaler<font face='Lucida Console'>(</font><font color='#0000FF'>this</font><font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>wm<font face='Lucida Console'>)</font>,
            have_last_keypress<font face='Lucida Console'>(</font><font color='#979000'>false</font><font face='Lucida Console'>)</font>,
            tie_input_events<font face='Lucida Console'>(</font><font color='#979000'>false</font><font face='Lucida Console'>)</font>
        <b>{</b>  
            gui_img.<font color='#BB00BB'>set_image_clicked_handler</font><font face='Lucida Console'>(</font><font color='#5555FF'>*</font><font color='#0000FF'>this</font>, <font color='#5555FF'>&amp;</font>image_window::on_image_clicked<font face='Lucida Console'>)</font>;
            gui_img.<font color='#BB00BB'>disable_overlay_editing</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
            <font color='#BB00BB'>set_image</font><font face='Lucida Console'>(</font>img<font face='Lucida Console'>)</font>; 
            <font color='#BB00BB'>set_title</font><font face='Lucida Console'>(</font>title<font face='Lucida Console'>)</font>;
            <font color='#BB00BB'>show</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>; 
        <b>}</b>
        

        ~<b><a name='image_window'></a>image_window</b><font face='Lucida Console'>(</font>
        <font face='Lucida Console'>)</font>;

        <font color='#0000FF'>template</font> <font color='#5555FF'>&lt;</font> <font color='#0000FF'>typename</font> image_type <font color='#5555FF'>&gt;</font>
        <font color='#0000FF'><u>void</u></font> <b><a name='set_image'></a>set_image</b> <font face='Lucida Console'>(</font>
            <font color='#0000FF'>const</font> image_type<font color='#5555FF'>&amp;</font> img
        <font face='Lucida Console'>)</font> 
        <b>{</b> 
            <font color='#0000FF'>const</font> <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> padding <font color='#5555FF'>=</font> <font color='#BB00BB'>scrollable_region_style_default</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>.<font color='#BB00BB'>get_border_size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
            auto_mutex <font color='#BB00BB'>M</font><font face='Lucida Console'>(</font>wm<font face='Lucida Console'>)</font>;
            gui_img.<font color='#BB00BB'>set_image</font><font face='Lucida Console'>(</font>img<font face='Lucida Console'>)</font>; 

            <font color='#009900'>// Only ever mess with the size of the window if the user is giving us an image
</font>            <font color='#009900'>// that is a different size.  Otherwise we assume that they will have already
</font>            <font color='#009900'>// sized the window to whatever they feel is reasonable for an image of the
</font>            <font color='#009900'>// current size.  
</font>            <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>previous_image_size <font color='#5555FF'>!</font><font color='#5555FF'>=</font> <font color='#BB00BB'>get_rect</font><font face='Lucida Console'>(</font>img<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>
            <b>{</b>
                <font color='#0000FF'>const</font> rectangle r <font color='#5555FF'>=</font> gui_img.<font color='#BB00BB'>get_image_display_rect</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
                <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>image_rect <font color='#5555FF'>!</font><font color='#5555FF'>=</font> r<font face='Lucida Console'>)</font>
                <b>{</b>
                    <font color='#009900'>// set the size of this window to match the size of the input image
</font>                    <font color='#BB00BB'>set_size</font><font face='Lucida Console'>(</font>r.<font color='#BB00BB'>width</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>+</font>padding<font color='#5555FF'>*</font><font color='#979000'>2</font>,r.<font color='#BB00BB'>height</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>+</font>padding<font color='#5555FF'>*</font><font color='#979000'>2</font><font face='Lucida Console'>)</font>;

                    <font color='#009900'>// call this to make sure everything else is setup properly
</font>                    <font color='#BB00BB'>on_window_resized</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;

                    image_rect <font color='#5555FF'>=</font> r;
                <b>}</b>
                previous_image_size <font color='#5555FF'>=</font> <font color='#BB00BB'>get_rect</font><font face='Lucida Console'>(</font>img<font face='Lucida Console'>)</font>;
            <b>}</b>
        <b>}</b>

        <font color='#0000FF'><u>void</u></font> <b><a name='add_overlay'></a>add_overlay</b> <font face='Lucida Console'>(</font>
            <font color='#0000FF'>const</font> overlay_rect<font color='#5555FF'>&amp;</font> overlay
        <font face='Lucida Console'>)</font>;

        <font color='#0000FF'>template</font> <font color='#5555FF'>&lt;</font><font color='#0000FF'>typename</font> pixel_type<font color='#5555FF'>&gt;</font>
        <font color='#0000FF'><u>void</u></font> <b><a name='add_overlay'></a>add_overlay</b><font face='Lucida Console'>(</font><font color='#0000FF'>const</font> rectangle<font color='#5555FF'>&amp;</font> r, pixel_type p<font face='Lucida Console'>)</font> 
        <b>{</b> <font color='#BB00BB'>add_overlay</font><font face='Lucida Console'>(</font>image_display::<font color='#BB00BB'>overlay_rect</font><font face='Lucida Console'>(</font>r,p<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>; <b>}</b>

        <font color='#0000FF'>template</font> <font color='#5555FF'>&lt;</font><font color='#0000FF'>typename</font> pixel_type<font color='#5555FF'>&gt;</font>
        <font color='#0000FF'><u>void</u></font> <b><a name='add_overlay'></a>add_overlay</b><font face='Lucida Console'>(</font><font color='#0000FF'>const</font> rectangle<font color='#5555FF'>&amp;</font> r, pixel_type p, <font color='#0000FF'>const</font> std::string<font color='#5555FF'>&amp;</font> l<font face='Lucida Console'>)</font> 
        <b>{</b> <font color='#BB00BB'>add_overlay</font><font face='Lucida Console'>(</font>image_display::<font color='#BB00BB'>overlay_rect</font><font face='Lucida Console'>(</font>r,p,l<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>; <b>}</b>

        <font color='#0000FF'>template</font> <font color='#5555FF'>&lt;</font><font color='#0000FF'>typename</font> pixel_type<font color='#5555FF'>&gt;</font>
        <font color='#0000FF'><u>void</u></font> <b><a name='add_overlay'></a>add_overlay</b><font face='Lucida Console'>(</font><font color='#0000FF'>const</font> std::vector<font color='#5555FF'>&lt;</font>rectangle<font color='#5555FF'>&gt;</font><font color='#5555FF'>&amp;</font> r, pixel_type p<font face='Lucida Console'>)</font> 
        <b>{</b> 
            std::vector<font color='#5555FF'>&lt;</font>overlay_rect<font color='#5555FF'>&gt;</font> temp;
            temp.<font color='#BB00BB'>resize</font><font face='Lucida Console'>(</font>r.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
            <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font><font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> i <font color='#5555FF'>=</font> <font color='#979000'>0</font>; i <font color='#5555FF'>&lt;</font> temp.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>i<font face='Lucida Console'>)</font>
                temp[i] <font color='#5555FF'>=</font> <font color='#BB00BB'>overlay_rect</font><font face='Lucida Console'>(</font>r[i], p<font face='Lucida Console'>)</font>;

            <font color='#BB00BB'>add_overlay</font><font face='Lucida Console'>(</font>temp<font face='Lucida Console'>)</font>;
        <b>}</b>

        <font color='#0000FF'><u>void</u></font> <b><a name='add_overlay'></a>add_overlay</b><font face='Lucida Console'>(</font>
            <font color='#0000FF'>const</font> full_object_detection<font color='#5555FF'>&amp;</font> object,
            <font color='#0000FF'>const</font> std::vector<font color='#5555FF'>&lt;</font>std::string<font color='#5555FF'>&gt;</font><font color='#5555FF'>&amp;</font> part_names
        <font face='Lucida Console'>)</font> 
        <b>{</b> 

            <font color='#BB00BB'>add_overlay</font><font face='Lucida Console'>(</font><font color='#BB00BB'>overlay_rect</font><font face='Lucida Console'>(</font>object.<font color='#BB00BB'>get_rect</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>, <font color='#BB00BB'>rgb_pixel</font><font face='Lucida Console'>(</font><font color='#979000'>255</font>,<font color='#979000'>0</font>,<font color='#979000'>0</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;

            std::vector<font color='#5555FF'>&lt;</font>overlay_circle<font color='#5555FF'>&gt;</font> temp;
            temp.<font color='#BB00BB'>reserve</font><font face='Lucida Console'>(</font>object.<font color='#BB00BB'>num_parts</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
            <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font><font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> i <font color='#5555FF'>=</font> <font color='#979000'>0</font>; i <font color='#5555FF'>&lt;</font> object.<font color='#BB00BB'>num_parts</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>i<font face='Lucida Console'>)</font>
            <b>{</b>
                <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>object.<font color='#BB00BB'>part</font><font face='Lucida Console'>(</font>i<font face='Lucida Console'>)</font> <font color='#5555FF'>!</font><font color='#5555FF'>=</font> OBJECT_PART_NOT_PRESENT<font face='Lucida Console'>)</font>
                <b>{</b>
                    <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>i <font color='#5555FF'>&lt;</font> part_names.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>
                        temp.<font color='#BB00BB'>push_back</font><font face='Lucida Console'>(</font><font color='#BB00BB'>overlay_circle</font><font face='Lucida Console'>(</font>object.<font color='#BB00BB'>part</font><font face='Lucida Console'>(</font>i<font face='Lucida Console'>)</font>, <font color='#979000'>7</font>, <font color='#BB00BB'>rgb_pixel</font><font face='Lucida Console'>(</font><font color='#979000'>0</font>,<font color='#979000'>255</font>,<font color='#979000'>0</font><font face='Lucida Console'>)</font>, part_names[i]<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
                    <font color='#0000FF'>else</font>
                        temp.<font color='#BB00BB'>push_back</font><font face='Lucida Console'>(</font><font color='#BB00BB'>overlay_circle</font><font face='Lucida Console'>(</font>object.<font color='#BB00BB'>part</font><font face='Lucida Console'>(</font>i<font face='Lucida Console'>)</font>, <font color='#979000'>7</font>, <font color='#BB00BB'>rgb_pixel</font><font face='Lucida Console'>(</font><font color='#979000'>0</font>,<font color='#979000'>255</font>,<font color='#979000'>0</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
                <b>}</b>
            <b>}</b>

            <font color='#BB00BB'>add_overlay</font><font face='Lucida Console'>(</font>temp<font face='Lucida Console'>)</font>;
        <b>}</b>

        <font color='#0000FF'><u>void</u></font> <b><a name='add_overlay'></a>add_overlay</b><font face='Lucida Console'>(</font>
            <font color='#0000FF'>const</font> full_object_detection<font color='#5555FF'>&amp;</font> object
        <font face='Lucida Console'>)</font> 
        <b>{</b> 
            std::vector<font color='#5555FF'>&lt;</font>std::string<font color='#5555FF'>&gt;</font> part_names;
            <font color='#BB00BB'>add_overlay</font><font face='Lucida Console'>(</font>object, part_names<font face='Lucida Console'>)</font>;
        <b>}</b>

        <font color='#0000FF'><u>void</u></font> <b><a name='add_overlay'></a>add_overlay</b><font face='Lucida Console'>(</font>
            <font color='#0000FF'>const</font> std::vector<font color='#5555FF'>&lt;</font>full_object_detection<font color='#5555FF'>&gt;</font><font color='#5555FF'>&amp;</font> objects,
            <font color='#0000FF'>const</font> std::vector<font color='#5555FF'>&lt;</font>std::string<font color='#5555FF'>&gt;</font><font color='#5555FF'>&amp;</font> part_names
        <font face='Lucida Console'>)</font> 
        <b>{</b> 
            std::vector<font color='#5555FF'>&lt;</font>overlay_rect<font color='#5555FF'>&gt;</font> rtemp;
            rtemp.<font color='#BB00BB'>reserve</font><font face='Lucida Console'>(</font>objects.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
            <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font><font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> i <font color='#5555FF'>=</font> <font color='#979000'>0</font>; i <font color='#5555FF'>&lt;</font> objects.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>i<font face='Lucida Console'>)</font>
            <b>{</b>
                rtemp.<font color='#BB00BB'>push_back</font><font face='Lucida Console'>(</font><font color='#BB00BB'>overlay_rect</font><font face='Lucida Console'>(</font>objects[i].<font color='#BB00BB'>get_rect</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>, <font color='#BB00BB'>rgb_pixel</font><font face='Lucida Console'>(</font><font color='#979000'>255</font>,<font color='#979000'>0</font>,<font color='#979000'>0</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
            <b>}</b>

            <font color='#BB00BB'>add_overlay</font><font face='Lucida Console'>(</font>rtemp<font face='Lucida Console'>)</font>;

            std::vector<font color='#5555FF'>&lt;</font>overlay_circle<font color='#5555FF'>&gt;</font> temp;

            <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font><font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> i <font color='#5555FF'>=</font> <font color='#979000'>0</font>; i <font color='#5555FF'>&lt;</font> objects.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>i<font face='Lucida Console'>)</font>
            <b>{</b>
                <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font><font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> j <font color='#5555FF'>=</font> <font color='#979000'>0</font>; j <font color='#5555FF'>&lt;</font> objects[i].<font color='#BB00BB'>num_parts</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>j<font face='Lucida Console'>)</font>
                <b>{</b>
                    <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>objects[i].<font color='#BB00BB'>part</font><font face='Lucida Console'>(</font>j<font face='Lucida Console'>)</font> <font color='#5555FF'>!</font><font color='#5555FF'>=</font> OBJECT_PART_NOT_PRESENT<font face='Lucida Console'>)</font>
                    <b>{</b>
                        <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>j <font color='#5555FF'>&lt;</font> part_names.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>
                            temp.<font color='#BB00BB'>push_back</font><font face='Lucida Console'>(</font><font color='#BB00BB'>overlay_circle</font><font face='Lucida Console'>(</font>objects[i].<font color='#BB00BB'>part</font><font face='Lucida Console'>(</font>j<font face='Lucida Console'>)</font>, <font color='#979000'>7</font>, <font color='#BB00BB'>rgb_pixel</font><font face='Lucida Console'>(</font><font color='#979000'>0</font>,<font color='#979000'>255</font>,<font color='#979000'>0</font><font face='Lucida Console'>)</font>,part_names[j]<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
                        <font color='#0000FF'>else</font>
                            temp.<font color='#BB00BB'>push_back</font><font face='Lucida Console'>(</font><font color='#BB00BB'>overlay_circle</font><font face='Lucida Console'>(</font>objects[i].<font color='#BB00BB'>part</font><font face='Lucida Console'>(</font>j<font face='Lucida Console'>)</font>, <font color='#979000'>7</font>, <font color='#BB00BB'>rgb_pixel</font><font face='Lucida Console'>(</font><font color='#979000'>0</font>,<font color='#979000'>255</font>,<font color='#979000'>0</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
                    <b>}</b>
                <b>}</b>
            <b>}</b>

            <font color='#BB00BB'>add_overlay</font><font face='Lucida Console'>(</font>temp<font face='Lucida Console'>)</font>;
        <b>}</b>

        <font color='#0000FF'><u>void</u></font> <b><a name='add_overlay'></a>add_overlay</b><font face='Lucida Console'>(</font>
            <font color='#0000FF'>const</font> std::vector<font color='#5555FF'>&lt;</font>full_object_detection<font color='#5555FF'>&gt;</font><font color='#5555FF'>&amp;</font> objects
        <font face='Lucida Console'>)</font> 
        <b>{</b> 
            std::vector<font color='#5555FF'>&lt;</font>std::string<font color='#5555FF'>&gt;</font> part_names;
            <font color='#BB00BB'>add_overlay</font><font face='Lucida Console'>(</font>objects, part_names<font face='Lucida Console'>)</font>;
        <b>}</b>

        <font color='#0000FF'><u>void</u></font> <b><a name='add_overlay'></a>add_overlay</b> <font face='Lucida Console'>(</font>
            <font color='#0000FF'>const</font> overlay_line<font color='#5555FF'>&amp;</font> overlay
        <font face='Lucida Console'>)</font>;

        <font color='#0000FF'><u>void</u></font> <b><a name='add_overlay'></a>add_overlay</b> <font face='Lucida Console'>(</font>
            <font color='#0000FF'>const</font> overlay_circle<font color='#5555FF'>&amp;</font> overlay
        <font face='Lucida Console'>)</font>;

        <font color='#0000FF'>template</font> <font color='#5555FF'>&lt;</font><font color='#0000FF'>typename</font> pixel_type<font color='#5555FF'>&gt;</font>
        <font color='#0000FF'><u>void</u></font> <b><a name='add_overlay'></a>add_overlay</b><font face='Lucida Console'>(</font><font color='#0000FF'>const</font> point<font color='#5555FF'>&amp;</font> p1, <font color='#0000FF'>const</font> point<font color='#5555FF'>&amp;</font> p2, pixel_type p<font face='Lucida Console'>)</font> 
        <b>{</b> <font color='#BB00BB'>add_overlay</font><font face='Lucida Console'>(</font>image_display::<font color='#BB00BB'>overlay_line</font><font face='Lucida Console'>(</font>p1,p2,p<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>; <b>}</b>

        <font color='#0000FF'><u>void</u></font> <b><a name='add_overlay'></a>add_overlay</b> <font face='Lucida Console'>(</font>
            <font color='#0000FF'>const</font> std::vector<font color='#5555FF'>&lt;</font>overlay_rect<font color='#5555FF'>&gt;</font><font color='#5555FF'>&amp;</font> overlay
        <font face='Lucida Console'>)</font>;

        <font color='#0000FF'><u>void</u></font> <b><a name='add_overlay'></a>add_overlay</b> <font face='Lucida Console'>(</font>
            <font color='#0000FF'>const</font> std::vector<font color='#5555FF'>&lt;</font>overlay_line<font color='#5555FF'>&gt;</font><font color='#5555FF'>&amp;</font> overlay
        <font face='Lucida Console'>)</font>;

        <font color='#0000FF'><u>void</u></font> <b><a name='add_overlay'></a>add_overlay</b> <font face='Lucida Console'>(</font>
            <font color='#0000FF'>const</font> std::vector<font color='#5555FF'>&lt;</font>overlay_circle<font color='#5555FF'>&gt;</font><font color='#5555FF'>&amp;</font> overlay
        <font face='Lucida Console'>)</font>;

        <font color='#0000FF'><u>void</u></font> <b><a name='clear_overlay'></a>clear_overlay</b> <font face='Lucida Console'>(</font>
        <font face='Lucida Console'>)</font>;

        <font color='#0000FF'><u>bool</u></font> <b><a name='get_next_double_click'></a>get_next_double_click</b> <font face='Lucida Console'>(</font>
            point<font color='#5555FF'>&amp;</font> p,
            <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font><font color='#5555FF'>&amp;</font> mouse_button
        <font face='Lucida Console'>)</font>; 

        <font color='#0000FF'><u>void</u></font> <b><a name='tie_events'></a>tie_events</b> <font face='Lucida Console'>(</font>
        <font face='Lucida Console'>)</font>;

        <font color='#0000FF'><u>void</u></font> <b><a name='untie_events'></a>untie_events</b> <font face='Lucida Console'>(</font>
        <font face='Lucida Console'>)</font>;

        <font color='#0000FF'><u>bool</u></font> <b><a name='events_tied'></a>events_tied</b> <font face='Lucida Console'>(</font>
        <font face='Lucida Console'>)</font> <font color='#0000FF'>const</font>;

        <font color='#0000FF'><u>bool</u></font> <b><a name='get_next_double_click'></a>get_next_double_click</b> <font face='Lucida Console'>(</font>
            point<font color='#5555FF'>&amp;</font> p
        <font face='Lucida Console'>)</font> 
        <b>{</b>
            <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> mouse_button;
            <font color='#0000FF'>return</font> <font color='#BB00BB'>get_next_double_click</font><font face='Lucida Console'>(</font>p, mouse_button<font face='Lucida Console'>)</font>;
        <b>}</b>

        <font color='#0000FF'><u>bool</u></font> <b><a name='get_next_keypress'></a>get_next_keypress</b> <font face='Lucida Console'>(</font>
            <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font><font color='#5555FF'>&amp;</font> key,
            <font color='#0000FF'><u>bool</u></font><font color='#5555FF'>&amp;</font> is_printable,
            <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font><font color='#5555FF'>&amp;</font> state
        <font face='Lucida Console'>)</font>;

        <font color='#0000FF'><u>bool</u></font> <b><a name='get_next_keypress'></a>get_next_keypress</b> <font face='Lucida Console'>(</font>
            <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font><font color='#5555FF'>&amp;</font> key,
            <font color='#0000FF'><u>bool</u></font><font color='#5555FF'>&amp;</font> is_printable
        <font face='Lucida Console'>)</font>
        <b>{</b>
            <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> state;
            <font color='#0000FF'>return</font> <font color='#BB00BB'>get_next_keypress</font><font face='Lucida Console'>(</font>key,is_printable,state<font face='Lucida Console'>)</font>;
        <b>}</b>

    <font color='#0000FF'>private</font>:

        <font color='#0000FF'>virtual</font> base_window::on_close_return_code <b><a name='on_window_close'></a>on_window_close</b><font face='Lucida Console'>(</font>
        <font face='Lucida Console'>)</font>;

        <font color='#0000FF'><u>void</u></font> <b><a name='on_window_resized'></a>on_window_resized</b><font face='Lucida Console'>(</font>
        <font face='Lucida Console'>)</font>;
        
        <font color='#0000FF'><u>void</u></font> <b><a name='on_image_clicked'></a>on_image_clicked</b> <font face='Lucida Console'>(</font>
            <font color='#0000FF'>const</font> point<font color='#5555FF'>&amp;</font> p,
            <font color='#0000FF'><u>bool</u></font> is_double_click,
            <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> btn
        <font face='Lucida Console'>)</font>;

        <font color='#0000FF'>virtual</font> <font color='#0000FF'><u>void</u></font> <b><a name='on_keydown'></a>on_keydown</b> <font face='Lucida Console'>(</font>
            <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> key,
            <font color='#0000FF'><u>bool</u></font> is_printable,
            <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> state
        <font face='Lucida Console'>)</font>;

        <font color='#009900'>// restricted functions
</font>        <b><a name='image_window'></a>image_window</b><font face='Lucida Console'>(</font>image_window<font color='#5555FF'>&amp;</font><font face='Lucida Console'>)</font>;
        image_window<font color='#5555FF'>&amp;</font> <b><a name='operator'></a>operator</b><font color='#5555FF'>=</font> <font face='Lucida Console'>(</font>image_window<font color='#5555FF'>&amp;</font><font face='Lucida Console'>)</font>;

        image_display gui_img;
        rectangle image_rect;
        rectangle previous_image_size;
        <font color='#0000FF'><u>bool</u></font> window_has_closed;
        <font color='#0000FF'><u>bool</u></font> have_last_click;
        point last_clicked_point;
        <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> mouse_btn;
        rsignaler clicked_signaler;

        <font color='#0000FF'><u>bool</u></font> have_last_keypress;
        <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> next_key;
        <font color='#0000FF'><u>bool</u></font> next_is_printable;
        <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> next_state;
        <font color='#0000FF'><u>bool</u></font> tie_input_events;
    <b>}</b>;

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
<b>}</b>

<font color='#0000FF'>#ifdef</font> NO_MAKEFILE
<font color='#0000FF'>#include</font> "<a style='text-decoration:none' href='widgets.cpp.html'>widgets.cpp</a>"
<font color='#0000FF'>#endif</font>

<font color='#0000FF'>#endif</font> <font color='#009900'>// DLIB_WIDGETs_
</font>

</pre></body></html>